two matrix in one, condition...matlab

1 view (last 30 days)
Nejc
Nejc on 9 Apr 2013
Hello, I got 2 matrix
A=[1 10 3;1 12 4;2 5 10;2 6 14;5 14 13]; B=[1 1 4;1 10 16;1 12 15;1 18 1;2 5 11;2 6 7;2 8 16];
Output should be [1 10 3 16;1 12 4 15; 2 5 10 11;2 6 14 7] ;
Matrixes A and B must have same elements in column 1 and 2 (somekind intersect), and in 3rd and 4th column must write value that belong each row that are same in column 1 and 2.
Thanks in advance, Nejc

Accepted Answer

Cedric
Cedric on 9 Apr 2013
>> [C,ia,ib] = intersect(A(:,1:2),B(:,1:2),'rows') ;
>> result = [C, A(ia,3), B(ib,3)]
result =
1 10 3 16
1 12 4 15
2 5 10 11
2 6 14 7

More Answers (0)

Categories

Find more on Matrices and Arrays in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!