find few elements in vector

3 ビュー (過去 30 日間)
Kerim Khemraev
Kerim Khemraev 2016 年 11 月 15 日
コメント済み: Kerim Khemraev 2016 年 11 月 16 日
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

採用された回答

Geoff Hayes
Geoff Hayes 2016 年 11 月 15 日
Kerim - try using ismember or intersect to find those elements that are common to both arrays.

その他の回答 (2 件)

Roger Stafford
Roger Stafford 2016 年 11 月 15 日
[~,ia] = intersect(y,x);
ia contains indices with respect to y of elements that lie both in y and in x.
  1 件のコメント
Kerim Khemraev
Kerim Khemraev 2016 年 11 月 16 日
Thank you! It helped

サインインしてコメントする。


Kerim Khemraev
Kerim Khemraev 2016 年 11 月 16 日
Geoff Hayes, Roger Stafford Thank you a lot! intersect function solves my problem

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by