how to find a float number

9 visualizaciones (últimos 30 días)
Suzuki
Suzuki el 20 de Sept. de 2021
Comentada: Suzuki el 20 de Sept. de 2021
I have a data (saved as double), as in the attache file. I need to find for example if a certain float number (for ex. -0.334) exist or no.
find(y7==-0.3340)
but because the nubers actully exist as -0.3440099999999 or sth like that, I can't find.
I have tried to change the format, but it did'nt solve the problem.
Any suggestions??

Respuesta aceptada

per isakson
per isakson el 20 de Sept. de 2021
Editada: per isakson el 20 de Sept. de 2021
find( abs( y7 -(-0.3340) ) < tol )
You choose tol. See eps - Floating-point relative accuracy

Más respuestas (1)

Walter Roberson
Walter Roberson el 20 de Sept. de 2021
[is_there, idx] = ismembertol(-0.3340, y7) %options allow you to control tolerances
y7(idx)
Also,
[~, idx] = min(abs(y7(:) - (-0.3340)));
y7(idx)
will show you the y7 that is closest to -0.3340, even if it is not very close. Whereas the ismembertol() will only return results if the value is within tolerance
  1 comentario
Suzuki
Suzuki el 20 de Sept. de 2021
that solve the problem, thanks alot.

Iniciar sesión para comentar.

Categorías

Más información sobre Debugging and Analysis en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by