Find different arrays in a matrix

1 visualización (últimos 30 días)
EldaEbrithil
EldaEbrithil el 20 de Ag. de 2020
Editada: EldaEbrithil el 20 de Ag. de 2020
Hi all
i have a matrix like that A=[1 2 3; 4 5 6; 7 8 9] i want the index of the rows that contain B=[1 3;4 5;7 9;4 6;2 3] so in this case the rows are:1, 2, 3, 2, 1
Thank you for the help
Regards
  1 comentario
EldaEbrithil
EldaEbrithil el 20 de Ag. de 2020
I have tried
[r,c]=ismember(A,B,'rows')
but it gives me error due to the fact that B and A must have the same dimension

Iniciar sesión para comentar.

Respuesta aceptada

David Hill
David Hill el 20 de Ag. de 2020
A=[1 2 3; 4 5 6; 7 8 9];
B=[1 3;4 5;7 9;4 6;2 3];
a=zeros(size(B,1),1);
for k=1:size(B,1)
a(k)=find(sum(ismember(A,B(k,:)),2));
end
  1 comentario
EldaEbrithil
EldaEbrithil el 20 de Ag. de 2020
Editada: EldaEbrithil el 20 de Ag. de 2020
Hi David thank you for answer me
i also found a solition of this type:
A = [1 14 24;2 15 25;1 16 72;1 14 24] % A sample matrix for demonstration...
c=[14 24;15 25;14 24]
[rig,col]=size(c);
for i=1:rig
I(:,i) = double(ismember(A(:,2:3),c(i,:),'rows'));
end
[rig,colo]=ind2sub(size(I),find(I>0))
the only inconvenient is that, due to the fact that A contain repeated lines, I is a unitary matrix that contains multiple (in this case two) ones in the same column( in this case in the first and last columns)
1 0 1
0 1 0
0 0 0
1 0 1
i don't want that, i want a single one for each column: i could i remove the multiple one in the columns? Whether it is the first one in the first or last row makes no difference, the important thing is that there is only one per column

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by