Deleting rows of a matrix based on values from another matrix
25 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I have a m x 3 matrix A, and a nx1 matrix B. I need to remove those rows of A if either column 1 or 2 of the matrix equals any value in B.
0 comentarios
Respuesta aceptada
Johan
el 8 de Jul. de 2022
A = randi(5,5,3)
B = randi(5,2,1)
% Find all the row where col 1 to 2 of A have a value in B
mask = any(ismember(A(:,1:2),B),2)
A(mask,:) = [] % delete the rows of A according to the mask
0 comentarios
Más respuestas (1)
Kritarth Sinha
el 8 de Jul. de 2022
Editada: Kritarth Sinha
el 8 de Jul. de 2022
Hello Hari,
You can simply use nested loops and for each value in column 1 or 2,you can check that is present in matrix B and do it accordingly.
Hope this will help.
0 comentarios
Ver también
Categorías
Más información sobre Loops and Conditional Statements 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!