find few elements in vector

3 visualizaciones (últimos 30 días)
Kerim Khemraev
Kerim Khemraev el 15 de Nov. de 2016
Comentada: Kerim Khemraev el 16 de Nov. de 2016
Hi!
Let's assume that I have a vector y=[3 5 6 7 9] and x=[5 9] How can I get the indices of elements in 'y' that are equal to 'x' without using cycle? I mean if I had x=5 ('x' is a scalar) I would write something like y==x or find(y==x) but 'x' is a vector. Thank you in advance

Respuesta aceptada

Geoff Hayes
Geoff Hayes el 15 de Nov. de 2016
Kerim - try using ismember or intersect to find those elements that are common to both arrays.

Más respuestas (2)

Roger Stafford
Roger Stafford el 15 de Nov. de 2016
[~,ia] = intersect(y,x);
ia contains indices with respect to y of elements that lie both in y and in x.

Kerim Khemraev
Kerim Khemraev el 16 de Nov. de 2016
Geoff Hayes, Roger Stafford Thank you a lot! intersect function solves my problem

Categorías

Más información sobre Creating and Concatenating Matrices 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