MATLAB round function - how does it round .5 up or down?
How does MATLAB's round function work with .5? Like 5.5? Does it round up to 6, or round down to 5? The Mathworks page talking about this f开发者_开发百科unction says nothing about this, and the example doesn't help either!
Here is the mathworks page for the MATLAB round function:
mathworks round function page
Wikipedia knows:
round(X): round to nearest integer, trailing 5 rounds to the nearest integer away from zero. For example, round(2.5) returns 3; round(-2.5) returns -3.
There's a little more information on this scheme (Round half away from zero), and many others, in the article on rounding.
>> round([-0.5 0.5])
ans =
-1 1
please type 'round(0.5)' in matlab... more efficient than writing on here
This Rounding Functions Collection that is available on MATLAB Exchange might be of interest as well. It includes M-files/code for several rounding methods that are not included with MATLAB, and a pdf illustrating these together with the standard MATLAB rounding methods.
精彩评论