Why there is no truncate function in Matlab?

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일

2 개 추천

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

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개)

카테고리

도움말 센터File Exchange에서 Mathematics에 대해 자세히 알아보기

질문:

2017년 8월 24일

댓글:

2017년 8월 30일

Community Treasure Hunt

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

Start Hunting!

Translated by