two matrix in one, condition...matlab

1 visualización (últimos 30 días)
Nejc
Nejc el 9 de Abr. de 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

Respuesta aceptada

Cedric
Cedric el 9 de Abr. de 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

Más respuestas (0)

Categorías

Más información sobre Install Products en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by