[英]covariance of two vectors in matlab
I am trying to compute the covariance between two vectors in matlab: 我试图在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. 我只想要1个数字:两个向量之间的协方差。 How does one get this in matlab? 如何在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
. 如果您只有两个一维向量,那么您要查找的数字是cov
输出的(1,2)元素。 By definition, the covariance matrix contains variances on its diagonal and covariance values on off-diagonal values. 根据定义,协方差矩阵包含对角线上的方差和非对角线值上的协方差值。
I guess x
in one realization of a random variable, so is y
. 我猜x
在一个随机变量的实现中,所以是y
。 Then cov(x',y')
will give you the covariance matrix, where the diagonal entries are the variance of x
and y
, and the off diagonal element is the their covariance. 然后cov(x',y')
将给出协方差矩阵,其中对角线条目是x
和y
的方差,而非对角线元素是它们的协方差。 Note cov(x',y')
is symmetric matrix. 注意cov(x',y')
是对称矩阵。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.