how to compare 3 matrix
4 views (last 30 days)
Show older comments
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
0 Comments
Accepted Answer
Azzi Abdelmalek
on 22 Mar 2013
Edited: Azzi Abdelmalek
on 22 Mar 2013
a=A(:,1:2)
D=a(ismember(a,B(:,1:2),'rows') & ismember(a,C(:,1:2),'rows') ,:)
0 Comments
More Answers (0)
See Also
Categories
Find more on Matrices and Arrays 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!