find indices of elements in terms of another vector

Hi, I have two vectors that can be simplified as follows;
v1 v2
134 134
135 137
137
138
140
Now I would like to find the index of v2 in terms of v1, which results in as below:
v3
1
3
.
.
.
I tried to use find function, but I couldn't get it right. Can anyone help me to resolve it other than for loop? Thank you.
Minsoo

답변 (2개)

Fangjun Jiang
Fangjun Jiang 2011년 6월 26일

1 개 추천

help ismember()

댓글 수: 1

v1=[134 135 137 138 140]';
v2=[134 137]';
[TF,Index]=ismember(v2,v1)

댓글을 달려면 로그인하십시오.

Paulo Silva
Paulo Silva 2011년 6월 26일
m=[134
135
137
138
140]
n=[137
134]
[c ia ib]=intersect(m,n);
ia
You just want ia

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

질문:

2011년 6월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by