mean( ) command or function gives the mean or average value of vector or matrix or array elements, after reading this MATLAB mean topic, you will know the theory and examples.
Syntax:
mean(n)
- n can be a vector or matrix.
Example: To calculate the mean of vector elements.
n=[1,2]; mean(n)
Output:
ans = 1.5000
Example: To create a matrix and calculates the mean of each column.
n=[1,2,3;3,2,1;4,5,1] v=mean(n)
Output:
n = 1 2 3 3 2 1 4 5 1 v = 2.6667 3.0000 1.6667
Explanation:
- 2.6667, 3.0000 and 1.6667 is the mean value of the first, second and third column elements respectively.