array element not equal to equivalent double
13 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Pierre-Vincent
le 15 Nov 2022
Commenté : Pierre-Vincent
le 15 Nov 2022
I have the following code:
array=0.0001:0.0001:0.6;
x=0.0402
y=array(402)
test=x==y
the result of the test is 0 and I really don't understand why... Both are supposed to be double. Can somebody help?
(the final idea is to find the index of X in the array with the find function)
0 commentaires
Réponse acceptée
Matt J
le 15 Nov 2022
Modifié(e) : Matt J
le 15 Nov 2022
Because computers cannot do exact math. The difference between x and y beyond the 4th decimal place make this clear:
array=0.0001:0.0001:0.6;
x=0.0402
y=array(402)
x-y
Plus de réponses (0)
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!