Asked by Yun Zhang
on 18 Feb 2019

Any algorithm I can use to find the set of data?

Answer by madhan ravi
on 18 Feb 2019

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

index = ii(lo)

Sign in to comment.

Answer by John D'Errico
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
on 18 Feb 2019

madhan ravi
on 18 Feb 2019

[r,c]=find(A.'==B);

G=findgroups(c);

index = splitapply(@max,r,G).'

Sign in to comment.

Opportunities for recent engineering grads.

Apply Today
## 7 Comments

## madhan ravi (view profile)

Direct link to this comment:https://de.mathworks.com/matlabcentral/answers/445635-i-have-a-large-vector-i-would-like-to-find-a-set-of-data-which-is-a-subset-of-the-large-vector#comment_672565

## Geoff Hayes (view profile)

Direct link to this comment:https://de.mathworks.com/matlabcentral/answers/445635-i-have-a-large-vector-i-would-like-to-find-a-set-of-data-which-is-a-subset-of-the-large-vector#comment_672567

## Yun Zhang (view profile)

Direct link to this comment:https://de.mathworks.com/matlabcentral/answers/445635-i-have-a-large-vector-i-would-like-to-find-a-set-of-data-which-is-a-subset-of-the-large-vector#comment_672571

## madhan ravi (view profile)

Direct link to this comment:https://de.mathworks.com/matlabcentral/answers/445635-i-have-a-large-vector-i-would-like-to-find-a-set-of-data-which-is-a-subset-of-the-large-vector#comment_672573

## Yun Zhang (view profile)

Direct link to this comment:https://de.mathworks.com/matlabcentral/answers/445635-i-have-a-large-vector-i-would-like-to-find-a-set-of-data-which-is-a-subset-of-the-large-vector#comment_672575

## madhan ravi (view profile)

Direct link to this comment:https://de.mathworks.com/matlabcentral/answers/445635-i-have-a-large-vector-i-would-like-to-find-a-set-of-data-which-is-a-subset-of-the-large-vector#comment_672577

## John D'Errico (view profile)

Direct link to this comment:https://de.mathworks.com/matlabcentral/answers/445635-i-have-a-large-vector-i-would-like-to-find-a-set-of-data-which-is-a-subset-of-the-large-vector#comment_672579

Sign in to comment.