cov

Compute covariances.

Syntax

c = cov(x)

c = cov(x,scale)

c = cov(x,y)

c = cov(x,y,scale)

Inputs

x
Data sample.
Type: double
Dimension: vector | matrix
y
Data sample.
Type: double
Dimension: vector | matrix
scale
Scale flag.
Type: integer (0 (default) or 1)
Use scale=0 to divide by n-1 and scale=1 to divide by n, where n is the number of samples in the data vectors.
Dimension: integer

Outputs

c
Covariance.
Dimension: scalar | matrix

Example

a=[1,2,3,4;1,4,9,16;16,9,4,1;1,8,27,64];
b=[2,3,4;4,9,16;8,27,64;16,9,4];
c=cov(a,b)
c = [Matrix] 4 x 3
2.5    75  210  
15.833 27  58   
61.167 -25 -142 
155.5  -87 -426 

Comments

When x is a matrix c=cov(x) computes matrix c such that c(i,j) is the covariance of columns i and j of x.

When x and y are vectors c=cov(x,y) computes the covariance of the vectors.

When x and y are matrices c=cov(x,y) computes matrix c such that c(i,j) is the covariance of column i of x and column j of y.