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?
2 次查看(过去 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?
0 个评论
回答(1 个)
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!