How do I calculate the correlation between the rows two large matrices?

조회 수: 3 (최근 30일)
Hello,
I have two matrices, both 224000x150, and I need to calculate the correlation between each pair of matching rows.
I wanted to use something like that:
corr_values = corr (A(:,:)', B(:,:)');
row_to_row_corr = diag(corr_values);
but "corr_values" will then be 224000x224000 matrix, and it's too large for MATLAB
(I get the following error message:_
Error using *
Requested 224770x224770 (376.4GB) array exceeds maximum array size preference (31.8GB). This might cause MATLAB to become unresponsive.
Is there a solution to that, instead of doing it in a loop, row-by-row?
Thanks
  댓글 수: 2
Yohay Zvi
Yohay Zvi 2022년 11월 13일
I guess that in my case Bruno's answer is a smipler solution - thanks.

댓글을 달려면 로그인하십시오.

채택된 답변

Bruno Luong
Bruno Luong 2022년 11월 13일
편집: Bruno Luong 2022년 11월 13일
Just use the formula of correlation
% Fake data for testing
A = rand(10,5);
B = rand(10,5);
Ac = A - mean(A,2);
Bc = B - mean(B,2);
C = dot(Ac,Bc,2)./sqrt(dot(Ac,Ac,2).*dot(Bc,Bc,2))
C = 10×1
-0.4725 -0.6565 0.2420 0.6003 -0.2725 -0.4911 0.8741 -0.3146 -0.7271 -0.7583

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by