I could not find anywhere, how to calculate correlation between two arrays. Say I do have Array1 with X and Y values and also Array2 with X and Y values. I tried to do some calculation and inserting two same arrays and expecting the correlation to be 1, but the result was something like -0.16...

I would be glad for any suggestion. Btw. I've found this Correlation coefficient between two arrays of 2D points? but still didnt find anything what could help me.

  • 1
    $\begingroup$ To be clear, you want to compute the correlation between two matrices? Look into the RV coefficient, it is a multivariate extension of the R-squared. $\endgroup$
    – SlowLoris
    Commented May 11, 2016 at 15:36
  • $\begingroup$ Wel, I have two arrays full of data like this. [0] => Array ( [x] => 964 [y] => 844 ). The arrays are same size. And now I would like to find programmatically correlation between this. Was googling for RV coefficient matlab examples, but did not find anything useful. $\endgroup$ Commented May 11, 2016 at 15:49
  • $\begingroup$ I don't use MatLab, but you can do it in R using the coeffRV function in the FactoMineR package. $\endgroup$
    – SlowLoris
    Commented May 11, 2016 at 16:56

1 Answer 1


An array with 2 dimensions is a matrix. Since your arrays have 2 dimensions, you are looking to find the correlation between these two matrices.

Here is a question with answers in R: "Correlation between matrices in R"

Here is a question with answers in MATLAB: "Matlab correlation between two matrices"

  • $\begingroup$ Thanks for the answer, but I dont understand, why in one example I am getting output one value and in the other example I am getting an output matrix. And also, should this 2D array be stored in matrix as MAT[vec2(X,Y), vec2(X,Y)....] and so? Or what is the best way to store these X and Y values in the matrix to pass to matlab for example? $\endgroup$ Commented May 11, 2016 at 16:44
  • $\begingroup$ For those answers you need to read the MATLAB's documentation for the function you are using. For instance, here is the documentation for the function "corrcoef": se.mathworks.com/help/matlab/ref/corrcoef.html $\endgroup$
    – PM0087
    Commented May 12, 2016 at 12:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.