In MATLAB, why does arr==el sometimes fail to find element el in array arr?

45 Views Asked by At

In MATLAB R2016a, suppose that I define the array arr = -0.2:0.1:0.2. I may then find the location of the value el = 0.1 with the command idx = find(arr==el). This correctly yields idx = 4.

But now suppose that I define a larger array such as arr = -0.3:0.1:0.3. If I again try to find the location of the value el = 0.1 with the command idx = find(arr==el), I obtain an empty matrix. For some reason, MATLAB does not consider the 0.1-like element in arr to be equal to el = 0.1.

Why is this and how can I generate an array for which element-finding operations like the above work reliably?

0

There are 0 best solutions below