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?

3 次查看(过去 30 天)
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?

回答(1 个)

Jeremy
Jeremy 2019-12-5
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.

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by