S = std(A)
S = std(A,w)
S = std(A,w,'all')
S = std(A,w,dim)
S = std(A,w,vecdim)
S = std(___,nanflag)
A is a vector of observations,
then the standard deviation is a scalar.
A is a matrix whose columns
are random variables and whose rows are observations, then
a row vector containing the standard deviations corresponding to each
A is a multidimensional array,
std(A) operates along the first array dimension
whose size does not equal 1, treating the elements as vectors. The
size of this dimension becomes
1 while the sizes
of all other dimensions remain the same.
By default, the standard deviation is normalized by
N is the number of observations.
S = std( specifies
a weighting scheme for any of the previous syntaxes. When
= 0 (default),
S is normalized by
w = 1,
S is normalized
by the number of observations,
can be a weight vector containing nonnegative elements. In this case,
the length of
w must equal the length of the dimension
std is operating.
S = std(
computes the standard deviation over the dimensions specified in the vector
w is 0 or 1. For example, if
A is a matrix, then
computes the standard deviation over all elements in
every element of a matrix is contained in the array slice defined by dimensions 1
Create a matrix and compute the standard deviation of each column.
A = [4 -5 1; 2 3 5; -9 1 7]; S = std(A)
S = 1×3 7.0000 4.1633 3.0551
Create a 3-D array and compute the standard deviation along the first dimension.
A(:,:,1) = [2 4; -2 1]; A(:,:,2) = [9 13; -5 7]; A(:,:,3) = [4 4; 8 -3]; S = std(A)
S = S(:,:,1) = 2.8284 2.1213 S(:,:,2) = 9.8995 4.2426 S(:,:,3) = 2.8284 4.9497
Create a matrix and compute the standard deviation of each column according to a weight vector
A = [1 5; 3 7; -9 2]; w = [1 1 0.5]; S = std(A,w)
S = 1×2 4.4900 1.8330
Create a matrix and calculate the standard deviation along each row.
A = [6 4 23 -3; 9 -10 4 11; 2 8 -5 1]; S = std(A,0,2)
S = 3×1 11.0303 9.4692 5.3229
Create a 3-D array and compute the standard deviation over each page of data (rows and columns).
A(:,:,1) = [2 4; -2 1]; A(:,:,2) = [9 13; -5 7]; A(:,:,3) = [4 4; 8 -3]; S = std(A,0,[1 2])
S = S(:,:,1) = 2.5000 S(:,:,2) = 7.7460 S(:,:,3) = 4.5735
Create a vector and compute its standard deviation, excluding
A = [1.77 -0.005 3.98 -2.95 NaN 0.34 NaN 0.19]; S = std(A,'omitnan')
S = 2.2797
A— Input array
Input array, specified as a vector, matrix, or multidimensional
A is a scalar, then
A is a
Complex Number Support: Yes
Weight, specified as one of these values:
0 — Normalize by
N is the number of observations. If there
is only one observation, then the weight is 1.
1 — Normalize by
Vector made up of nonnegative scalar weights corresponding
to the dimension of
A along which the standard
deviation is calculated.
dim— Dimension to operate along
Dimension to operate along, specified as a positive integer scalar. If no value is specified, then the default is the first array dimension whose size does not equal 1.
dim indicates the dimension whose
length reduces to
while the sizes of all other dimensions remain the same.
Consider a two-dimensional input array,
dim = 1, then
a row vector containing the standard deviation of the elements in
dim = 2, then
a column vector containing the standard deviation of the elements
in each row.
dim is greater than
std(A) returns an array of zeros the same
vecdim— Vector of dimensions
Vector of dimensions, specified as a vector of positive integers. Each element represents a dimension of the input array. The lengths of the output in the specified operating dimensions are 1, while the others remain the same.
Consider a 2-by-3-by-3 input array,
std(A,0,[1 2]) returns a 1-by-1-by-3 array whose
elements are the standard deviations computed over each page of
NaN condition, specified as one of these
'includenan' — Include
when computing the standard deviation, resulting in
'omitnan' — Ignore
appearing in either the input array or weight vector.
datetime arrays, you can also use
omit and include
NaT values, respectively.
For a random variable vector A made up of N scalar observations, the standard deviation is defined as
where μ is the mean of A:
The standard deviation
is the square root of the variance. Some definitions of standard deviation
use a normalization factor of N instead of N-1,
which you can specify by setting
This function supports tall arrays with the limitation:
The weighting scheme cannot be a vector.
For more information, see Tall Arrays.
Usage notes and limitations:
If you specify
dim, then it must
be a constant.
See Variable-Sizing Restrictions for Code Generation of Toolbox Functions (MATLAB Coder).
This function fully supports GPU arrays. For more information, see Run MATLAB Functions on a GPU (Parallel Computing Toolbox).
This function fully supports distributed arrays. For more information, see Run MATLAB Functions with Distributed Arrays (Parallel Computing Toolbox).