Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

covariance of two vectors in matlab

I am trying to compute the covariance between two vectors in matlab:

x = [1:10]
y = [21:30]
cov(x,y)

This returns the matrix of covariance and variance. I just want 1 number: the covariance between the two vectors. How does one get this in matlab?

like image 204
Alex Avatar asked Sep 04 '12 22:09

Alex


People also ask

How do you find the covariance of two vectors?

The steps to find the covariance matrix for a sample are as follows: Find the sample variance for all datasets using the formula ∑n1(xi−¯¯¯x)2n−1 ∑ 1 n ( x i − x ¯ ) 2 n − 1 . Find the sample covariance between all pairs of datasets given by ∑n1(xi−¯¯¯x)(yi−¯¯¯y)n−1 ∑ 1 n ( x i − x ¯ ) ( y i − y ¯ ) n − 1 .

What is covariance of a matrix?

Covariance Matrix is a measure of how much two random variables gets change together. It is actually used for computing the covariance in between every column of data matrix. The Covariance Matrix is also known as dispersion matrix and variance-covariance matrix.

How do you find the coefficient of variation in MATLAB?

The formula for the coefficient of variation is: Coefficient of Variation = (Standard Deviation / Mean) * 100. In symbols: CV = (SD/x̄) * 100.


1 Answers

If you only have two one-dimensional vectors, the number you're looking for is the (1,2) element of the output of cov. By definition, the covariance matrix contains variances on its diagonal and covariance values on off-diagonal values.

like image 103
Ansari Avatar answered Sep 22 '22 16:09

Ansari