23.12.2012 Views

MATLAB Function Reference Volume 1: A - E - Bad Request

MATLAB Function Reference Volume 1: A - E - Bad Request

MATLAB Function Reference Volume 1: A - E - Bad Request

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

cov<br />

2cov<br />

Purpose Covariance matrix<br />

Syntax C = cov(X)<br />

C = cov(x,y)<br />

Description C = cov(x) where x is a vector returns the variance of the vector elements. For<br />

matrices where each row is an observation and each column a variable, cov(x)<br />

is the covariance matrix. diag(cov(x)) is a vector of variances for each<br />

column, and sqrt(diag(cov(x))) is a vector of standard deviations.<br />

2-344<br />

C = cov(x,y), where x and y are column vectors of equal length, is equivalent<br />

to cov([x y]).<br />

Remarks cov removes the mean from each column before calculating the result.<br />

The covariance function is defined as<br />

where E is the mathematical expectation and µ i =<br />

Exi .<br />

Examples Consider A = [-1 1 2 ; -2 3 1 ; 4 0 3]. To obtain a vector of variances for<br />

each column of A:<br />

See Also corrcoef, mean, std<br />

cov( x1 ,x2 ) = E[ ( x1 – µ 1)<br />

( x2 – µ 2)<br />

]<br />

v = diag(cov(A))'<br />

v =<br />

10.3333 2.3333 1.0000<br />

Compare vector v with covariance matrix C:<br />

C =<br />

10.3333 -4.1667 3.0000<br />

-4.1667 2.3333 -1.5000<br />

3.0000 -1.5000 1.0000<br />

The diagonal elements C(i,i) represent the variances for the columns of A.<br />

The off-diagonal elements C(i,j) represent the covariances of columns i and<br />

j.<br />

xcorr, xcov in the Signal Processing Toolbox

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!