How To Calculate Standard Deviation in MATLAB?
Last Updated :
10 Nov, 2022
Standard deviation is a statistical quantity that tells us how much-distributed data is from its mean value. Standard deviation can also be defined as the square root of the Variance of the same data.
Standard Deviation in MATLAB:
MATLAB provides a simple function to calculate the standard deviation of data, the std() function, which is very similar to the var() function which calculates the variance of data. The syntax of std() function is:
std_dev = std(<data>, <weight>, …)
Where, <data> is the data in the form of an array or vector and <weight> is an optional argument, which stores the weights of the corresponding data.
Let us understand the std() function with examples and see how to calculate the standard deviation of different types of data.
Example 1:
Matlab
data = 23:55;
std_dev = std(data);
disp(std_dev)
|
Output:
Let us find the standard deviation when the same data as above have weights.
Example 2:
Matlab
data = 23:55;
w = linspace(0.5,2.1,33);
std_dev = std(data,w);
disp(std_dev)
|
Output:
MATLAB also allows the calculation of the standard variance of a multidimensional vector along a particular dimension (less than the maximum dimension) as follows.
Example 3:
Matlab
data = [23 55 32; 1 3 5; 9 13 8.25];
std_dev = std(data,0, "all" );
disp(std_dev)
std_dev = std(data,0,1);
disp(std_dev)
std_dev = std(data,0,2);
disp(std_dev)
|
Output:
Share your thoughts in the comments
Please Login to comment...