0.48 and 0.72 not detected in the array
1 次查看(过去 30 天)
显示 更早的评论
Hi,
I have attached varmat.mat. In this array, I can find any other elements in the array using find (SessionData.CoherenceTypes == 0.08) for example.
whenever I want to look for 0.48 or 0.72 using SessionData.CoherenceTypes == 0.48 or SessionData.CoherenceTypes == 0.72, the vector returned is empty although 0.48 and 0.72 are in the row vector. I tried in multiple computers and those two values are not detected.
Please suggest what was the problem. thanks.
1 个评论
Stephen23
2023-1-24
"Please suggest what was the problem."
This is a completely expected result with binary floating point numbers:
This is highly recommended reading material as well:
回答(1 个)
the cyclist
2023-1-24
编辑:the cyclist
2023-1-24
Due to floating point precision, the values are not exactly 0.48. For example,
load("varmat.mat","SessionData")
SessionData.CoherenceTypes(256) - 0.48
When doing comparison for floating point numbers, you need to check for equality within a tolerance.
See, for example, this documentation for details about floating point numbers and how to deal with them.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Detection 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!