find few elements in vector

조회 수: 4 (최근 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

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by