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?
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.