two matrix in one, condition...matlab

16 vues (au cours des 30 derniers jours)
Nejc
Nejc le 9 Avr 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

Réponse acceptée

Cedric
Cedric le 9 Avr 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

Plus de réponses (0)

Catégories

En savoir plus sur MATLAB dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by