## Hot to find the matched values between two vectors and also related indeces

### Juster (view profile)

on 17 Jun 2012
Accepted Answer by Juster

### Juster (view profile)

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.

## Products

No products are associated with this question.

on 18 Jun 2012

Thanks

per isakson

### per isakson (view profile)

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?

Jan Simon

### Jan Simon (view profile)

on 18 Jun 2012

Look for Bruno's "ismemberf" in the FEX.

Juster

### Juster (view profile)

on 20 Jun 2012

Hello Jam, I solved thanks to the 'ismemberf' function.

Best regards.

### Andrei Bobrov (view profile)

Answer by Andrei Bobrov

### Andrei Bobrov (view profile)

on 17 Jun 2012
```[idx,loc] = ismember(b,a);
out = loc(idx);
```

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

Juster

### Juster (view profile)

on 18 Jun 2012

Hi Andrei I send you a personal message.

Thanks

### Juster (view profile)

on 17 Jun 2012

I tried it but with microsecond order it did'n work.

In fact if you try with :

a = [0:10e-6:280e-6]; b = [0 80e-6 170e-6 250e-6]; [idx,loc] = ismember(b,a); out = loc(idx);

I don't got the right values of indices.