Is it a bug?
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Haixiao Xian
le 9 Fév 2020
Commenté : Star Strider
le 9 Fév 2020
I found a weird situation with the number "1.4"
v=0:0.01:5;
vd=1.4;
a=0;
for i=1:length(v)
if v(i)==vd
a=1
end
end
This code doesn't make the value of "a" become "1." However, if I change the value of "vd" to any other numbers (eg. vd=1.5), this code works well. Also, if I change the range of "v" to "v=0:0.01:2", it works as well. I don't know what's wrong with my orignal codes. Can anyone help me? Thank you very much!
0 commentaires
Réponse acceptée
Star Strider
le 9 Fév 2020
You have encountered ‘floating-point approximation error’.
0 commentaires
Plus de réponses (1)
Image Analyst
le 9 Fév 2020
Yes, you do have a bug in your program.
You compared floating point numbers with == instead of ismembertol().
Voir également
Catégories
En savoir plus sur Logical 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!