Correlation with two matrices
20 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi everyone,
I would like to find the correlation about two matrices the same dimensions. I have two matrices with 64 channles and I need to find the correlation between the first value of first matrix and the first, second, third.... until sixty-four value of second matrix and viceversa.
How can I do this?
Thanks a lot!
0 comentarios
Respuestas (2)
David Hill
el 12 de Dic. de 2022
You could just manually do it yourself.
A=randi(100,10);B=randi(100,10);
M=mean(A);N=mean(B);
r=zeros(size(A,2),size(B,2));
for m=1:size(A,2)
for n=1:size(B,2)
r(m,n)=sum((A(:,m)-M(m)).*(B(:,n)-N(n)))/sqrt(sum((A(:,m)-M(m)).^2.*(B(:,n)-N(n)).^2));
end
end
r
0 comentarios
Bora Eryilmaz
el 12 de Dic. de 2022
Editada: Bora Eryilmaz
el 12 de Dic. de 2022
You can compute the pairwise correlation between columns of matrices as follows:
% Data matrics with 64 channels (columns)
A = rand(10,64);
B = rand(10,64);
% Vector of pairwise correlation values
C = corr(A,B); % All pairs of columns
C = diag(C) % Matching pairs of columns
3 comentarios
Bora Eryilmaz
el 14 de Dic. de 2022
Editada: Bora Eryilmaz
el 14 de Dic. de 2022
Your code seems unnecessarily complicated. If you already have the matrices L and R, the correlations variable need not be a cell array. Something like this should work:
% Data matrics with 64 channels (columns)
L = rand(100,64);
R = rand(100,64);
% Vector of pairwise correlation values
C = corr(L,R); % All pairs of columns
correlations = diag(C) % Matching pairs of columns
The second loop that goes over the columns of L and R matrices is not needed since the corr() command already handles that for you, given the whole matrices. Unless of course if your L and R "matrices" have a more complicated structure, like being cell arrays, etc.
Ver también
Categorías
Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!