round off to nearest 5 instead of 10

74 views (last 30 days)
Ben
Ben on 9 Dec 2014
Commented: John D'Errico on 4 Oct 2020
is that any way to round off to nearest 5 instead of 10? for example, round off 346 to 345; 293 to 295; 296 to 295;
thx for help :p
  3 Comments
Aiman Waheed
Aiman Waheed on 4 Oct 2020
How can I get round nearest tenth in Matlab
John D'Errico
John D'Errico on 4 Oct 2020
@Aiman Waheed:
Use round. READ THE HELP FOR ROUND. Unless you have an old release of MATLAB, round has allowed you to round to any number of digits for some years now.
Note that you cannot round to an EXACT decimal, since MATLAB does not store numbers in a decimal form.

Sign in to comment.

Accepted Answer

Adam
Adam on 9 Dec 2014
Edited: Adam on 9 Dec 2014
round( x / 5 ) * 5;
  2 Comments
Ben
Ben on 9 Dec 2014
thanks!!! why i never think in this way!
Adam
Adam on 9 Dec 2014
Well, it isn't always easy. I asked a question on creating a matrix to which the answer provided by Rick Rosson was similarly trivial a few months ago, but only if your thought process takes you in that direction!

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!