Borrar filtros
Borrar filtros

Find rows where one column value matches with any value inside another array

14 visualizaciones (últimos 30 días)
I am new to Matlab, so please respond even if the question is trivial
I have a matrix. Lets say matrix is
A =[
16 2 3 13
5 11 10 8
9 7 6 12
4 14 15 1]
I have an array. Lets say array is
B = [3, 6, 15]
I want to find out all the rows of Matrix A where column 3 value of Matrix A matches with any value mentioned in the array B. In the above case output will be
ans = [
16 2 3 13
9 7 6 12
4 14 15 1]
I don't want to use loop for this calculation. Is there any built in function which does this.
Thanks

Respuesta aceptada

Star Strider
Star Strider el 7 de Ag. de 2016
This works:
A =[16 2 3 13
5 11 10 8
9 7 6 12
4 14 15 1];
B = [3, 6, 15];
idx = ismember(A(:,3),B);
Result = A(idx,:)
Result =
16 2 3 13
9 7 6 12
4 14 15 1

Más respuestas (0)

Categorías

Más información sobre Multidimensional Arrays en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by