how to find a float number

조회 수: 9 (최근 30일)
Suzuki
Suzuki 2021년 9월 20일
댓글: Suzuki 2021년 9월 20일
I have a data (saved as double), as in the attache file. I need to find for example if a certain float number (for ex. -0.334) exist or no.
find(y7==-0.3340)
but because the nubers actully exist as -0.3440099999999 or sth like that, I can't find.
I have tried to change the format, but it did'nt solve the problem.
Any suggestions??

채택된 답변

per isakson
per isakson 2021년 9월 20일
편집: per isakson 2021년 9월 20일
find( abs( y7 -(-0.3340) ) < tol )
You choose tol. See eps - Floating-point relative accuracy
  댓글 수: 1
Suzuki
Suzuki 2021년 9월 20일
brilliant, thanks...

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Walter Roberson
Walter Roberson 2021년 9월 20일
[is_there, idx] = ismembertol(-0.3340, y7) %options allow you to control tolerances
y7(idx)
Also,
[~, idx] = min(abs(y7(:) - (-0.3340)));
y7(idx)
will show you the y7 that is closest to -0.3340, even if it is not very close. Whereas the ismembertol() will only return results if the value is within tolerance
  댓글 수: 1
Suzuki
Suzuki 2021년 9월 20일
that solve the problem, thanks alot.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Debugging and Analysis에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by