how to find correlation between different dimension matrices in matlab

5.1k views Asked by At

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?

1

There are 1 answers

0
herohuyongtao On BEST ANSWER

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.