Finding the indices of the elements of one array in another
8 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Deepa Maheshvare
el 20 de En. de 2022
Editada: Deepa Maheshvare
el 20 de En. de 2022
Given two vectors A and B,
I want to find the index of elements of B in A
I tried
A = ["G1", "V2", "G3", "G4", "V1"]
B = ["V1", "G4"];
[sharedvals,idxs] = intersect(A, B, 'stable')
The above returns
idxs =
4
5
Expected result:
idxs =
5
4
Could someone suggest how to obtain the expected result?
Respuesta aceptada
Rik
el 20 de En. de 2022
You muct have thought of this already (as it is one of your tags), but ismember does what you need:
A = ["G1", "V2", "G3", "G4", "V1"];
B = ["V1", "G4"];
[sharedvals,idxs] = ismember(B,A)
If you want a column vector you can transpose it.
1 comentario
Más respuestas (0)
Ver también
Categorías
Más información sobre Logical 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!