while loop and nan causing inifinite loop
조회 수: 2 (최근 30일)
이전 댓글 표시
I have the following code
now what happens when i run this is that the while loop doesn't ever stop and op ends up equal to (NaN NaN). i'm not exactly sure what's wrong.
i figured that i could simply try to exit the while loop if the value was nan by sayign that if np(1) or np(2) was equal to nan than np(1) would equal fp(1) and the while loop would stop, but i can't seem to do that either... could anyoen help me?
댓글 수: 0
채택된 답변
Walter Roberson
2013년 1월 9일
편집: Walter Roberson
2013년 1월 9일
use isnan() to test for nan. Do not compare to nan using "=" or "~="
By the way, it appears to me that you should perhaps use atan2() instead of the tan() and range tests you have.
댓글 수: 0
추가 답변 (1개)
Matt J
2013년 1월 9일
Use the dbstop command
>>dbstop if naninf
to detect where the NaNs are introduced.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 NaNs에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!