MATLAB: How to compare 3 matrix

comparingcomparing 3 matrixesMATLABmatrix

Hi
I got 3 matrixes, each different vertical dimension (mx3,nx3,px3). What I need to do is to compare first and second column in all 3 matrixes. If first and second data in a row match in all 3 matrixes, than i have to extract that in new matrix. How I do that.
Here are examples of matrixes:
A=[1 22 501;1 23 224;2 15 6;2 13 221;2 6 14; 3 2 10; 3 12 50];
B=[1 22 5;1 26 33;2 14 10;2 15 13;2 6 14; 3 2 166; 3 12 60; 4 7 12];
C=[1 2 14;1 22 15;2 23 6;2 15 20;2 6 14; 3 2 11; 3 5 100; 3 12 0; 4 7 12;]
The result must come:
D=[1 22; 2 15; 2 6;3 2;3 12]
Thank you very much in advance. Nejc

Best Answer

a=A(:,1:2)
D=a(ismember(a,B(:,1:2),'rows') & ismember(a,C(:,1:2),'rows') ,:)