Rounding decimals matlab manipulates
2 次查看(过去 30 天)
显示 更早的评论
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
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
2017-8-2
mod() is also a built in function like round(), fix(), int32(), ceil(), floor(), etc.
回答(1 个)
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!