MATLAB: Two matrix in one, condition…matlab

codition rowintersectMATLABmatrixes

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

Best Answer

>> [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