Matrix matching function

markjohns

New Member
Joined
Jul 12, 2019
Messages
3
I created an x by y non-symmetric matrix in which, for values 1-5, "O" denotes a "preference to match". A "match" occurs only if both values reciprocate the preference (1 and 2 are a "match" because both prefer the other, while 1 and 3 are NOT a match because the preference isn't reciprocated).

[TABLE="width: 500"]
<tbody>[TR]
[TD="align: center"][/TD]
[TD="align: center"]1[/TD]
[TD="align: center"]2[/TD]
[TD="align: center"]3[/TD]
[TD="align: center"]4[/TD]
[TD="align: center"]5[/TD]
[TD="align: center"].[/TD]
[TD="align: center"].[/TD]
[TD="align: center"].[/TD]
[TD="align: center"]x[/TD]
[/TR]
[TR]
[TD="align: center"]1[/TD]
[TD="align: center"]NULL[/TD]
[TD="align: center"]O[/TD]
[TD="align: center"]-[/TD]
[TD="align: center"]O[/TD]
[TD="align: center"]O[/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[/TR]
[TR]
[TD="align: center"]2[/TD]
[TD="align: center"]O[/TD]
[TD="align: center"]NULL[/TD]
[TD="align: center"]O[/TD]
[TD="align: center"]O[/TD]
[TD="align: center"]O[/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[/TR]
[TR]
[TD="align: center"]3[/TD]
[TD="align: center"]O[/TD]
[TD="align: center"]-[/TD]
[TD="align: center"]NULL[/TD]
[TD="align: center"]-[/TD]
[TD="align: center"]O[/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[/TR]
[TR]
[TD="align: center"]4[/TD]
[TD="align: center"]O[/TD]
[TD="align: center"]-[/TD]
[TD="align: center"]O[/TD]
[TD="align: center"]NULL[/TD]
[TD="align: center"]O[/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[/TR]
[TR]
[TD="align: center"]5[/TD]
[TD="align: center"]O[/TD]
[TD="align: center"]O[/TD]
[TD="align: center"]O[/TD]
[TD="align: center"]O[/TD]
[TD="align: center"]NULL[/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[/TR]
[TR]
[TD="align: center"].[/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"]NULL[/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[/TR]
[TR]
[TD="align: center"].[/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"]NULL[/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[/TR]
[TR]
[TD="align: center"].[/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"]NULL[/TD]
[TD="align: center"][/TD]
[/TR]
[TR]
[TD="align: center"]y[/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"]NULL[/TD]
[/TR]
</tbody>[/TABLE]

1 and 2 match
1 and 4 match
1 and 5 match
2 and 5 match
3 and 5 match
4 and 5 match
1 and 3 do NOT match
2 and 3 do NOT match
2 and 4 do NOT match
3 and 4 do NOT match

First question - Is there a "match" function that lists the unique 1x1 set of matches?
Second question - Is there an "iterative match" function that lists the unique set of matches after 'n' iterations?

For example, since 1 and 4 both match with 5, then I would like to group 1, 4, and 5. I'd like the function to apply to an x by y matrix and have matches for 1 by 1, 1 by 1 by 1, 1 by 1 by 1 by ... z iterations.
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Welcome to the forum.

Interesting question. Try:


Book1
ABCDEFGHIJKLM
1123456..xMatches
21NULLO-OOO01&02
32ONULLOOO-01&04
43O-NULL-O-01&05
54O-ONULLOO02&05
65OOOONULLO03&05
7.NULL04&05
8.NULL
9.NULL
10yNULL
11
Sheet3
Cell Formulas
RangeFormula
M2{=IFERROR(TEXT(SMALL(IFERROR(IF(ROW($B$2:$G$6)$B$2:$G$6),IF($B$2:$G$6=TRANSPOSE($B$2:$G$6),(ROW($B$2:$G$6)-ROW($B$2)+1)*100+COLUMN($B$2:$G$6)-COLUMN($B$2)+1)),""),ROWS($M$2:$M2)),"00&00"),"")}
Press CTRL+SHIFT+ENTER to enter array formulas.


This seems to work with your example. However, it might be better accomplished with VBA. And your second question seems like it would absolutely require VBA. I'm not exactly sure of your requirements, but it seems like you'd like to take a subset of the rows and columns based on the results of the matches, create a smaller array then repeat until you hit some stopping condition.
 
Upvote 0
That works really well. Very neat.

[TABLE="width: 544"]
<colgroup><col span="12"><col></colgroup><tbody>[TR]
[TD] [/TD]
[TD]1[/TD]
[TD]2[/TD]
[TD]3[/TD]
[TD]4[/TD]
[TD]5[/TD]
[TD]6[/TD]
[TD]7[/TD]
[TD]8[/TD]
[TD]9[/TD]
[TD]10[/TD]
[TD] [/TD]
[TD] [/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]Null[/TD]
[TD]O[/TD]
[TD] [/TD]
[TD]O[/TD]
[TD]O[/TD]
[TD] [/TD]
[TD] [/TD]
[TD]O[/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD]01&02[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]O[/TD]
[TD]Null[/TD]
[TD]O[/TD]
[TD]O[/TD]
[TD]O[/TD]
[TD]O[/TD]
[TD]O[/TD]
[TD]O[/TD]
[TD]O[/TD]
[TD]O[/TD]
[TD] [/TD]
[TD]01&04[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D] [/TD]
[TD] [/TD]
[TD]07&09[/TD]
[/TR]
[TR]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD]08&09

[/TD]
[/TR]
</tbody>[/TABLE]
Thank you. I'll post another question regarding the VBA. Really appreciate it. Cheers!
 
Upvote 0
Consider the last match of your example 8 & 9. These are matching 2 spaces, not 2 Os. Is that what you wanted, or did you only want to match Os? Also, a caveat. The table must start on A1, or B2, or C3, or D4, etc. I can also fix the formula to handle other starting cells if that's an issue.
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top