Asked by Juster
on 17 Jun 2012

Good evening to all,

I have two vectors, for example:

a = [0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27]; b= [0 8 17 25];

what I would find are the indices related the vector 'a' with the same value of 'b'...like for example in this case 1 9 18 26.

Thanks in advance.

*No products are associated with this question.*

Answer by Juster
on 18 Jun 2012

Accepted answer

Any answer please?

Thanks

per isakson
on 18 Jun 2012

The proposed solution, ismember, works with whole numbers.

With floating point numbers rounding comes in and it's a different problem.

Did you search the File Exchange?

Answer by Andrei Bobrov
on 17 Jun 2012

[idx,loc] = ismember(b,a); out = loc(idx);

**ADD** after Knot's answer

out = find(any(abs(bsxfun(@minus,a,b.')) < eps(100)));

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi test

Learn moreOpportunities for recent engineering grads.

Apply Today
## 0 Comments