find rows of two matricies (of different sizes) based on matching element of one column
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Adam
el 10 de Nov. de 2015
Comentada: Adam
el 10 de Nov. de 2015
Given two matrices A[1000x4] and B[500x4] what is the fastest way in MATLAB to extract the complete rows of A which share the same element values in column 4 as B does?
for example if,
A=[1 2 3 7;
2 6 9 1;
8 3 4 8] and
B=[9 2 5 1;
6 2 1 5;
3 6 6 8].
What is the most efficient way to create a new array
C=[2 6 9 1;
8 3 4 8],
having the rows of A with same element in column 4 as B does?
Thanks!
0 comentarios
Respuesta aceptada
Image Analyst
el 10 de Nov. de 2015
Try ismember():
A=[1 2 3 7;
2 6 9 1;
8 3 4 8]
B=[9 2 5 1;
6 2 1 5;
3 6 6 8]
[ia, ib] = ismember(A(:,4), B(:, 4))
C = A(find(ib),:)
Más respuestas (1)
James Tursa
el 10 de Nov. de 2015
Caution, untested:
k = ismember(A(:,4),B(:,4));
C = A(k,:);
0 comentarios
Ver también
Categorías
Más información sobre Shifting and Sorting Matrices en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!