median( ) command or function gives the median value of vector or matrix or array elements, after reading this MATLAB median topic, you will know the theory and examples.
Syntax:
median(n)
- n can be any vector or matrix.
Example: To find the median value of the vector.
n=[1,2,2,10,5,78] median(n)
Output:
n = 1 2 2 10 5 78 ans = 3.5000
Example: To find the median value of each column of the matrix.
n=[1,2,3;1,2,23;4,5,21] median(n)
Output:
n = 1 2 3 1 2 23 4 5 21 ans = 1 2 21
Explanation:
- 1, 2 and 21 are the median value of the first, second and third column of the matrix respectively.