How to quickly find the indecies of elements in an array?

2 visualizaciones (últimos 30 días)
Benson Gou
Benson Gou el 23 de Mayo de 2021
Comentada: Torsten el 23 de Mayo de 2021
Dear All,
I have an array A which contains integers. I have another array B. I want to find out the indecis of B in A.
For example, A = [1 9 2 8 3 7 4 6 5], B = [5 6 7]. The indecis of B in A is [9 8 6].
Thanks.
Benson

Respuesta aceptada

per isakson
per isakson el 23 de Mayo de 2021
Editada: per isakson el 23 de Mayo de 2021
A = [1 9 2 8 3 7 4 6 5];
B = [5 6 7];
[~,ix] = ismember( B, A )
ix = 1×3
9 8 6

Más respuestas (1)

Torsten
Torsten el 23 de Mayo de 2021
indices = find(A==B)
  2 comentarios
Benson Gou
Benson Gou el 23 de Mayo de 2021
Hi, Torsten,
I got an error message: Matrix dimensions must agree.
Thanks.
Benson
Torsten
Torsten el 23 de Mayo de 2021
Ok, seems a loop is required to find the indices for more than one element using the "find" command.

Iniciar sesión para comentar.

Categorías

Más información sobre Downloads 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