how to compare 3 matrix

4 次查看(过去 30 天)
Nejc
Nejc 2013-3-22
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

采纳的回答

Azzi Abdelmalek
Azzi Abdelmalek 2013-3-22
编辑:Azzi Abdelmalek 2013-3-22
a=A(:,1:2)
D=a(ismember(a,B(:,1:2),'rows') & ismember(a,C(:,1:2),'rows') ,:)

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrices and Arrays 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by