Given these two matrices:
m1 = [ 1 1;
2 2;
3 3;
4 4;
5 5 ];
m2 = [ 4 2;
1 1;
4 4;
7 5 ];
I’m looking for a function, such as:
indices = GetIntersectionIndecies (m1,m2);
That the output of which will be
indices =
1
0
0
1
0
How can I find the intersection indices of rows between these two matrices without using a loop ?
One possible solution:
By the way, I love the inventive solution of @Shai, and it is much faster than my solution if your matrices are small. But if your matrices are large, then my solution will dominate. This is because if we set
T = size(m1, 1), then thetmpvariable in the answer of @Shai will be T*T, ie a very large matrix ifTis large. Here’s some code for a quick speed test:Set
T = 10andM = 1000, and we get:But set
T = 1000andM = 100and we get: