Statistics Toolbox | ![]() ![]() |
Syntax
C = cov(X)
C = cov(x,
y)
Description
C = cov(X)
computes the covariance matrix. For a single vector, cov(x)
returns a scalar containing the variance. For matrices, where each row is an observation, and each column a variable, cov(X)
is the covariance matrix.
The variance function, var(X)
is the same as diag(cov(X)).
The standard deviation function, std(X)
is equivalent to sqrt(diag(cov(X)))
.
cov(x,y)
, where x
and y
are column vectors of equal length, gives the same result as cov([x y])
.
The cov
function is part of the standard MATLAB language.
Algorithm
[n,
p] = size(X); X = X - ones(n,
1)* mean
(X); Y = X'
*X/(n-1);
See Also
xcov
, xcorr
(Signal Processing Toolbox)
![]() | corrcoef | crosstab | ![]() |