0

I have 2 matrices of dim 15*3 and 10*3 . I want to find their correlation (Pearson coefficient) between the 2 matrices. I used the command

result=corr2(A,B)

But i got the error stating that A and B of same size.

Can anyone tell me what is wrong in that command. Is there any other way to find correlation between 2 different dimension matrices?

herohuyongtao
  • 49,413
  • 29
  • 133
  • 174
Keerthana
  • 157
  • 4
  • 18
  • Correlation between two sets of data will require them to be the same size by definition - since you're trying to see how similar their (pairs of) entries behave. Maybe tell us what your ultimate goal is? – adalca Jan 05 '14 at 16:56

1 Answers1

3

For r = corr2(A,B) (documentation):

  • it returns the correlation coefficient r between A and B, where A and B are matrices or vectors of the same size. r is a scalar double.

  • If you still want to use corr2, you can do like:

    result = corr2(A(1:10, :), B)
    

Solve: for matrices of different dimensions, you should use xcorr2:

C = xcorr2(A, B)

documentation:

  • C = xcorr2(A,B) returns the cross-correlation of matrices A and B with no scaling. xcorr2 is the two-dimensional version of xcorr.
herohuyongtao
  • 49,413
  • 29
  • 133
  • 174