MATLAB Answers

Having an array V from 0 to 44.8 in steps of 0.01, I try to use the function find(V == 30) and I get and empty array. Why?

1 view (last 30 days)
Andrea Maldonado
Andrea Maldonado on 5 Dec 2019
Answered: Jeremy on 5 Dec 2019
If I try to look for the index of any other value below 22 I get the correct index, but when I try to look for any value greater than 22 I get a 1*0 empty double row vector. Why is this happening?? Is it a bug?
Following array is being used:
Volt = 0:0.01:44.8
find(Volt == 2) %works perfectly
find(Volt == 20.5) %works as well
find(Volt == 30) %doesn't work even when the value is contained in the array, how do I find the index?

Answers (1)

Jeremy
Jeremy on 5 Dec 2019
I suspect this is a case of roundoff error. A workaround would be
find(Volt > 29.999 & Volt < 30.001);
Using whatever tolerance you want, it doesn't have to be 1e-3.

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!