Why there is no truncate function in Matlab?

62 visualizaciones (últimos 30 días)
Vidz
Vidz el 24 de Ag. de 2017
Comentada: Vidz el 30 de Ag. de 2017
Hi,
I need to truncate values in a For loop and round() isn't working. I was just wondering why there is no truncate function yet?

Respuesta aceptada

Image Analyst
Image Analyst el 24 de Ag. de 2017
Because round sometimes rounds up - away from zero. I think you may want to use fix() instead of round(). It always rounds towards zero, in other words, truncates. See if that works for you and let me know.
  2 comentarios
Walter Roberson
Walter Roberson el 24 de Ag. de 2017
You should also know about floor(), which rounds towards negative infinity -- the maximum integer less than or equal to the input.
Vidz
Vidz el 30 de Ag. de 2017
Thanks for your help, fix() works. Can do x=x-rem(x,0.001) as well.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by