Cross correlation of Matrix columns

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 comentarios

Bob Thompson
Bob Thompson el 18 de Abr. de 2018
Editada: Bob Thompson el 18 de Abr. de 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
Antonis Asiminas el 18 de Abr. de 2018
Editada: Antonis Asiminas el 18 de Abr. de 2018
The default type of correlation for function corr is Pearson. If I want correlate column 1 and column 2 of my matrix M, I would type PearsCorr=corr(M(:,1),M(:,2)). That would give me a single value which corresponds to r correlation coefficient. Hope that helps. :)
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
Antonis Asiminas el 18 de Abr. de 2018
That makes absolute sense. I was so hung up on having the diagonal going from (size(M,2),1) to (1,size(M,2)) that I didn't see the easy answer. I'll just invert the matrix Cor I get and I'm done. Thank you very much! :)
Michael de la Maza
Michael de la Maza el 4 de Feb. de 2022
corrcoef(M)

Iniciar sesión para comentar.

Respuestas (0)

Preguntada:

el 18 de Abr. de 2018

Comentada:

el 4 de Feb. de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by