‎07-18-2018 06:22 AM
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.
Solved! Go to Solution.
‎07-18-2018 10:31 AM - edited ‎07-18-2018 10:34 AM
‎07-18-2018 10:58 AM
‎07-19-2018 10:03 AM - edited ‎07-19-2018 10:21 AM
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.
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.