Finding common elements in two matrices of different lengths
29 views (last 30 days)
Show older comments
Greetings, I’ve a question about comparing matrices 'a' and 'b' then creating a third matrix 'c' based on matching pairs of numbers in two other matrices. Current example:
a = [17,9;23,3;24,3;23,3;24,3;9,6;10,6;23,3;24,3;23,3]
b = [17,1;18,1;21,1;23,3;24,3;23,4;24,4;9,6;10,6;14,12;23,12;24,12;23,14]
My goal is to create 'c' where both columns in 'a' and 'b' are the same. So, row 1 of 'a' would be excluded, as would the first 2 rows of 'b', etc. etc.. Any help with accomplishing this task would be greatly appreciated.
Cheers, Jason
0 Comments
Accepted Answer
Walter Roberson
on 10 May 2018
It is not clear what output you want, considering you have two inputs. Perhaps
c = intersect(a,b,'rows');
or
c = [ismember(a,b,'rows'); ismember(b,a,'rows')];
More Answers (0)
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!