How do I calculate the correlation between the rows two large matrices?
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Yohay Zvi
am 13 Nov. 2022
Kommentiert: Yohay Zvi
am 13 Nov. 2022
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 Kommentare
Karim
am 13 Nov. 2022
You can try to use sparse matrices.
More information --> Create sparse matrix - MATLAB sparse - MathWorks Benelux
Akzeptierte Antwort
Bruno Luong
am 13 Nov. 2022
Bearbeitet: Bruno Luong
am 13 Nov. 2022
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))
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!