Note: This page has been translated by MathWorks. Please click here

To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

Median value of array

`M = median(A)`

`M = median(A,dim)`

`M = median(___,nanflag)`

`M = median(`

returns
the median value of `A`

)`A`

.

If

`A`

is a vector, then`median(A)`

returns the median value of`A`

.If

`A`

is a nonempty matrix, then`median(A)`

treats the columns of`A`

as vectors and returns a row vector of median values.If

`A`

is an empty 0-by-0 matrix,`median(A)`

returns`NaN`

.If

`A`

is a multidimensional array, then`median(A)`

treats the values along the first array dimension whose size does not equal`1`

as vectors. The size of this dimension becomes`1`

while the sizes of all other dimensions remain the same.

`median`

computes natively in the numeric class
of `A`

, such that `class(M) = class(A)`

.

For ordinal categorical arrays, MATLAB^{®} interprets the median
of an even number of elements as follows:

If the number of categories between the middle two values is ... | Then the median is ... |
---|---|

zero (values are from consecutive categories) | larger of the two middle values |

an odd number | value from category occurring midway between the two middle values |

an even number | value from larger of the two categories occurring midway between the two middle values |

Was this topic helpful?