## I have a large vector, I would like to find a set of data which is a subset of the large vector.

### Yun Zhang (view profile)

on 18 Feb 2019
Latest activity Commented on by madhan ravi

on 18 Feb 2019
Any algorithm I can use to find the set of data?

Yun Zhang

### Yun Zhang (view profile)

on 18 Feb 2019
Sorry, it is a typo. It should be 5

on 18 Feb 2019
;-) shouldn’t it be 5&6?
John D'Errico

### John D'Errico (view profile)

on 18 Feb 2019
No reason to add an answer for no reason. Moved to acomment:
"I meant the first index should be 5"

### Tags

on 18 Feb 2019

[lo,ii]=ismember(B,A);
index = ii(lo)

### John D'Errico (view profile)

on 18 Feb 2019

ismember is exactly the tool to solve your problem.
A = [1 3 5 7 9 8 6 4 2];
B = [5 6];
[LIA,LOCB] = ismember(A,B)
LIA =
1×9 logical array
0 0 1 0 0 0 1 0 0
LOCB =
0 0 1 0 0 0 2 0 0
So we see that elements 3 and 7 of A are in B.
find(LIA)
ans =
3 7
And that seems to be what you are asking to learn.

Yun Zhang

### Yun Zhang (view profile)

on 18 Feb 2019
ismember is not the right tool. The data I searched has to be in the right order. for instance, B=[5 6] and A=[ 1 3 5 7 6 5 6]. The search result has to be index 6 and 7.