Why there is no truncate function in Matlab?

67 次查看(过去 30 天)
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?

采纳的回答

Image Analyst
Image Analyst 2017-8-24
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 个评论
Walter Roberson
Walter Roberson 2017-8-24
You should also know about floor(), which rounds towards negative infinity -- the maximum integer less than or equal to the input.
Vidz
Vidz 2017-8-30
Thanks for your help, fix() works. Can do x=x-rem(x,0.001) as well.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Multidimensional Arrays 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by