Rounding decimals matlab manipulates

조회 수: 2 (최근 30일)
yuval ohayon
yuval ohayon 2017년 7월 31일
댓글: Image Analyst 2017년 8월 2일
I need to write, in 1 code line, given a number (pos, neg, int, float), how do I round it without preset functions like fix, round, etc.?
  댓글 수: 9
Steven Lord
Steven Lord 2017년 8월 2일
In general people on MATLAB Answers don't post answers to homework questions or questions that sound like homework. If you show what you've done to try to solve the problem on your own and ask a specific question about where you're having difficulty you may receive some more specific suggestions.
Of course, if this isn't a homework problem, just use the round function or the other rounding functions included in MATLAB.
Image Analyst
Image Analyst 2017년 8월 2일
mod() is also a built in function like round(), fix(), int32(), ceil(), floor(), etc.

댓글을 달려면 로그인하십시오.

답변 (1개)

Jan
Jan 2017년 8월 1일
Try it:
x = 13.3
y = mod(x, 1)
z = 13.6
y = mod(x, 1)
Now you should see how to use the output to decide, if the rest of the division by 1 is lower or higher than 0.5.
  댓글 수: 3
Walter Roberson
Walter Roberson 2017년 8월 1일
x - mod(x,1) + mod(x,1)>0.5
Jan
Jan 2017년 8월 2일
int64() rounds also. And you can use cast() to preserve the original class.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by