Quickly compute a the column by column correlation between large matrices.
Create two large matrices
A = rand(100, 5000);
B = rand(100, 5000);
Meausre the time required to compute the column by column correlation using:
tic;
C1 = corr_col(A,B);
t1 = toc;
tic;
C2 = diag(corr(A,B));
t2 = toc;
tic;
C3 = zeros(size(A,1),1);
for i = 1:size(A,2);
C3(i) = corr(A(:,i), B(:,i));
end
t3 = toc;
Results:
col_corr: 0.0080 seconds
diag+corr: 0.1953 seconds
loop+corr: 1.0560 seconds
Difference between results:
col_corr vs diag+corr: 0.1747e-12
loop+corr vs diag+corr: 0.1397e-12