Q:

Getting the index of a float number in a vector

I've executed this code, but it doesn't work as I expect:
A = 1:0.1:1.4

A =

    1.0000    1.1000    1.2000    1.3000    1.4000

A == 1.3000

ans =

    0     0     0     0     0

I thought I was going to get:
    ans =

        0     0     0     1     0

Why does it not work? And how can I make it work as I want?
Thank you.

A:

That's the usual when you compare floats. Try A(4)-1.3. It'll give you something small but not zero. That's because floats have finite precision. In general, it's better not to test for equality with floats.
The usual approach is to define a small tolerance (for example 1e-9) and compare taking that tolerance into account:
abs(A-1.3)<1e-9

