Why does MATLAB not finding a element from my matrix?
显示 更早的评论
x = 0.4:0.01:0.5
idx = find(x==0.41)
3 个评论
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.
Tshikaya
2024-3-27
Walter Roberson
2025-6-24
Note that the colon operator is handled as repeated addition, so 0.4, 0.4+0.1, 0.4+0.1+0.1, 0.4+0.1+0.1+0.1 and so on. Because double precision numbers operate in binary instead of in decimal, 0.1 cannot be exactly represented, and instead each 0.1 addition adds 0.1000000000000000055511151231257827021181583404541015625
Mathworks could have chosen an impletation of (initial value) + increment * (position in the sequence minus 1), so 0.4 + [0, 1, 2, 3, 4 ...] * 0.1 ... but Mathworks did not chose that (possibly for efficiency reasons.)
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Logical 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!