MATLAB: Finding common elements in two matrices of different lengths

common elementscompareequal elementsismember

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

Best Answer

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')];