取消
显示结果 
搜索替代 
您的意思是: 

correlation coefficient

已解决!
转到解答

Please tell how to program the correlation coefficient formula given in Matlab as described:

R=corrcoef(X) calculates a matrix R of correlation coefficients for
an array X, in which each row is an observation and each column is a
variable.

 and it is explained in Matlab as:

If C is the covariance matrix, C = COV(X), then corrcoef(X) is
the matrix whose (i,j)'th element is

C(i,j)/SQRT(C(i,i)*C(j,j)).

 

Please help.

 

 

 

0 项奖励
1 条消息(共 4 条)
4,087 次查看
解答
已被主题作者 canzie07 接受
2 条消息(共 4 条)
4,052 次查看
解答
已被主题作者 canzie07 接受

See if this works for you. 😄

 

CovCorr.png

3 条消息(共 4 条)
4,046 次查看

On a side note, compare efficiencies between the two solutions. Mine is much more efficient, especially for larger input arrays. For a NxN input matrix, I only take N square roots, while the other solution must take NxN square roots.

(Imagine a 1000x1000 input array. It would be the difference between 1000 and 1000000 square root operations!)

 

Also note that one could eliminate the second loop by using the outer product as follows.

 

CovCorrOuter.png

 

 

For a completely loop-free version, you could even get the diagonal directly, but it seems a bit clumsy... I would probably use the above instead.

 

CovCorrOuterDiag.png

4 条消息(共 4 条)
4,009 次查看