LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

correlation coefficient

Solved!
Go to solution

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 Kudos
Message 1 of 4
(2,710 Views)
Solution
Accepted by topic author canzie07
Message 2 of 4
(2,675 Views)
Solution
Accepted by topic author canzie07

See if this works for you. 😄

 

CovCorr.png

Message 3 of 4
(2,669 Views)

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

Message 4 of 4
(2,632 Views)