문제

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!

도움이 되었습니까?

해결책

If you can round to a multiple of 1, you can round to a multiple of N. Simply use

round(x/5)*5

다른 팁

The logic would be like [not sure of the syntax of MATLAB]

floor((x + 2.5)/5)

Edit:

floor((x + 2.5)/5) * 5
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top