Comparative Operator result is wrong

6 visualizaciones (últimos 30 días)
여춘 박
여춘 박 el 12 de Abr. de 2021
Comentada: Stephen23 el 12 de Abr. de 2021
I tried to run the if statement but this happens.
The result must be true(=1) in the last instruction but it returns false(=0)...
Anyone knows what is the problem???

Respuestas (3)

KSSV
KSSV el 12 de Abr. de 2021
Note that you are comparing two floating point numbers and such numbers cannot be comapred using ==. Follow
tol = 10^-5 ;
idx = abs(val1-val2)<tol

Steven Lord
Steven Lord el 12 de Abr. de 2021
Two numbers that are displayed the same may not represent the same stored value. See this Answers post for more information about floating point numbers.

Image Analyst
Image Analyst el 12 de Abr. de 2021

Categorías

Más información sobre Introduction to Installation and Licensing en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by