MATLAB Function Reference    
cov

Covariance matrix

Syntax

Description

C = cov(x) where x is a vector returns the variance of the vector elements. For matrices where each row is an observation and each column a variable, cov(x) is the covariance matrix. diag(cov(x)) is a vector of variances for each column, and sqrt(diag(cov(x))) is a vector of standard deviations.

C = cov(x,y), where x and y are column vectors of equal length, is equivalent to cov([x y]).

Remarks

cov removes the mean from each column before calculating the result.

The covariance function is defined as

where is the mathematical expectation and .

Examples

Consider A = [-1 1 2 ; -2 3 1 ; 4 0 3]. To obtain a vector of variances for each column of A:

Compare vector v with covariance matrix C:

The diagonal elements C(i,i) represent the variances for the columns of A. The off-diagonal elements C(i,j) represent the covariances of columns i and j.

See Also

corrcoef, mean, std

xcorr, xcov in the Signal Processing Toolbox


   coth cplxpair