while loop and nan causing inifinite loop
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have the following code
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/150380/image.png)
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 commentaires
Réponse acceptée
Walter Roberson
le 9 Jan 2013
Modifié(e) : Walter Roberson
le 9 Jan 2013
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 commentaires
Plus de réponses (1)
Matt J
le 9 Jan 2013
Use the dbstop command
>>dbstop if naninf
to detect where the NaNs are introduced.
0 commentaires
Voir également
Catégories
En savoir plus sur NaNs dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!