If you can round to a multiple of 1, you can round to a multiple of N. Simply use
round(x/5)*5
Question
Is there any MATLAB Function to round an a number to nearest integer divisible by 5?
What I want to do it, let say I have numbers from 0.3,4.7,7.6 and I want these numbers to be rounded to 0, 5, 10. Is there any function in MATLAB to do that?
Thanks!
Solution
If you can round to a multiple of 1, you can round to a multiple of N. Simply use
round(x/5)*5
OTHER TIPS
The logic would be like [not sure of the syntax of MATLAB]
floor((x + 2.5)/5)
Edit:
floor((x + 2.5)/5) * 5