Contents Previous Next Subchapters

Computing The Median
Syntax median(x)
See Also colmedian , colmean , sort , psort

Description
If x is a vector, returns a scalar containing the median of the elements of x Otherwise, returns a row vector with the same column dimension as x and containing the median of each of the columns of x. The argument x is an integer, real, or double-precision matrix. The return value is a double-precision vector.

The median of an even number of elements is the average of the two central values.

New programs should be converted to use the colmedian function. The median() function may be deprecated in future versions.

Example
If you enter
     x = {2, 3, 1}
     median(x)
O-Matrix returns
     2
If you enter
     x = [2, 4, 6, 8]
     median(x)
O-Matrix returns
     5