Finding all indices by ismember

Viewed 9313

This is what is described in one of the examples for ismember:

Define two vectors with values in common.

A = [5 3 4 2]; B = [2 4 4 4 6 8];

Determine which elements of A are also in B as well as their corresponding locations in B.

[Lia,Locb] = ismember(A,B)

The result is:

Lia =
     0     0     1     1

Locb =    
     0     0     2     1

The element in B with the lowest index that matches A(3) is B(2). A(4) equals B(1). Is there a way by which we could find all the indices of the elemets of B matching the same element in A?

5 Answers
Related