Why does MATLAB not finding a element from my matrix?
2 次查看(过去 30 天)
显示 更早的评论
x = 0.4:0.01:0.5
idx = find(x==0.41)
2 个评论
Dyuman Joshi
2024-3-27
Welcome to the world of floating point numbers! Here not all numbers can be represented exactly in binary form.
Stephen has provided an extensive list of material which you can refer to - for detailed information and explainations regarding the same.
采纳的回答
Stephen23
2024-3-27
移动:Dyuman Joshi
2024-3-27
Testing for exact equivalence of binary floating point numbers should be avoided.
Compare the values, are they actually the same? (hint: no):
x = 0.4:0.01:0.5;
fprintf('%.40f\n', x(2), 0.41)
The recommended approach is to compare the absolute difference against a tolerance:
tol = 1e-5;
abs(x(2)-0.41)<tol
More information on this topic:
This is worth reading as well:
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrices and Arrays 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!