cov
Compute covariances.
Syntax
c = cov(x)
c = cov(x,scale)
c = cov(x,y)
c = cov(x,y,scale)
Inputs
- x
- Data sample.
- y
- Data sample.
- scale
- Scale flag.
Outputs
- c
- Covariance.
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.