A is a vector of observations,
the variance is a scalar.
A is a matrix whose columns
are random variables and whose rows are observations,
a row vector containing the variances corresponding to each column.
A is a multidimensional array,
var(A) treats the values along the first array
dimension whose size does not equal 1 as vectors. The size of this
1 while the sizes of all other
dimensions remain the same.
The variance is normalized by the number of observations
A is a scalar,
A is a
V = var(___, specifies
a weighting scheme for any of the previous syntaxes. When
= 0 (default),
V is normalized by the
number of observations
w = 1,
it is normalized by the number of observations.
also be a weight vector containing nonnegative elements. In this case,
the length of
w must equal the length of the dimension
var is operating.
V = var(___, returns
the variance along the dimension
dim for any of
the previous syntaxes. To maintain the default normalization while
specifying the dimension of operation, set
w = 0 in
the second argument.
Create a matrix and compute its variance.
A = [4 -7 3; 1 4 -2; 10 7 9]; var(A)
ans = 21.0000 54.3333 30.3333
Create a 3-D array and compute its variance.
A(:,:,1) = [1 3; 8 4]; A(:,:,2) = [3 -4; 1 2]; var(A)
ans(:,:,1) = 24.5000 0.5000 ans(:,:,2) = 2 18
Create a matrix and compute its variance according to a weight vector
A = [5 -4 6; 2 3 9; -1 1 2]; w = [0.5 0.25 0.25]; var(A,w)
ans = 6.1875 9.5000 6.1875
Create a matrix and compute its variance along the first dimension.
A = [4 -2 1; 9 5 7]; var(A,0,1)
ans = 12.5000 24.5000 18.0000
Compute the variance of
A along the second dimension.
ans = 9 4
A— Input arrayvector | matrix | multidimensional array
Input array, specified as a vector, matrix, or multidimensional array.
Complex Number Support: Yes
Weight, specified as one of:
0 — normalizes by the number
-1. If there is only one observation,
the weight is 1.
1 — normalizes by the number
a vector made up of nonnegative scalar weights corresponding
to the dimension of
A along which the variance
dim— Dimension to operate alongpositive integer scalar
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 variance of the elements in each column.
dim = 2, then
a column vector containing the variance of the elements in each row.
var returns an array of zeros the same size
dim is greater than
includenan' (default) | ‘
NaN condition, specified as one of these
the variance of input containing
NaN values is
NaN values appearing in either the input array
or weight vector are ignored.
For a random variable vector A made up of N scalar observations, the variance is defined as
where μ is the mean of A,
Some definitions of
variance use a normalization factor of N instead
of N-1, which can be specified by setting
In either case, the mean is assumed to have the usual normalization