0.48 and 0.72 not detected in the array

조회 수: 1 (최근 30일)
HYZ
HYZ 2023년 1월 24일
댓글: Stephen23 2023년 1월 24일
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개)

the cyclist
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
ans = 5.5511e-17
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.

카테고리

Help CenterFile Exchange에서 Detection에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by