Cross correlation of Matrix columns
Show older comments
Hi,
thank you in advance for taking the time to read this. I have a problem for which I'm sure there is an easy answer but I cannot find it. I have a matrix M (n,m). Each column represents a different experimenter and each row different score. I would like to correlate the scores of each experimenter with the scores of themselves and all other experimenters, and create effectively a new matrix Cor (m,m). It's element of this matrix will be a single value corresponding to the Pearson correlation between each column pair. The diagonal (from m,1 to 1,m) will contain the auto correlations of all columns of matrix M. I understand that have this square matrix is redundant (mirror to the other half) but it looks good when shown as a coloured correlation Matrix. I think I can do that with several lines of code but I'd like to know if there's an easy way.
Best, Antonis
5 Comments
Bob Thompson
on 18 Apr 2018
Edited: Bob Thompson
on 18 Apr 2018
What type of correlation are you looking to make? I know you mentioned "Pearson," but I don't know what that actually looks like.
Antonis Asiminas
on 18 Apr 2018
Edited: Antonis Asiminas
on 18 Apr 2018
Bob Thompson
on 18 Apr 2018
Ok, so your Cor (m*m) matrix is a collection of those single values? Why not just run a pair of for loops then?
for m1 = 1:size(M,2); % Create correlations for each experimenter
for m2 = 1:size(M,2); % Correlate against each experimenter
Cor(m2,m1) = corr(M(:,m1),M(:,m2));
end
end
If this isn't what you're looking for, please feel free to explain more.
Antonis Asiminas
on 18 Apr 2018
Michael de la Maza
on 4 Feb 2022
corrcoef(M)
Answers (0)
Categories
Find more on Correlation and Convolution in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!