## Find the indeces of common elements of

### pietro (view profile)

on 2 Nov 2015
Latest activity Commented on by pietro

### pietro (view profile)

on 5 Nov 2015
Accepted Answer by Stephen Cobeldick

### Stephen Cobeldick (view profile)

Hi all,
I have two vectors and I need to find the index of the common elements between the two vectors, but the position of the indeces should be like the first array.
Here an example:
a=[7 10 33];
b=[33 7];
result=[3,1];
I would use setdiff like [C,ia] = setdiff(A,B,'stable'), but C has the same order of array A and I cannot swap A with B. In my case all the elements of B are always included in A.
Thank you
Regards
Pietro

### Stephen Cobeldick (view profile)

Answer by Stephen Cobeldick

### Stephen Cobeldick (view profile)

on 2 Nov 2015
Edited by Stephen Cobeldick

### Stephen Cobeldick (view profile)

on 2 Nov 2015

You can use bsxfun quite effectively for this:
>> a = [7,10,33];
>> b = [33,7];
>> [R,~] = find(bsxfun(@eq,a(:),b))
R =
3
1

pietro

on 5 Nov 2015
thanks!