Correlation with two matrices
20 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (2)
David Hill
am 12 Dez. 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 Kommentare
Bora Eryilmaz
am 12 Dez. 2022
Bearbeitet: Bora Eryilmaz
am 12 Dez. 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 Kommentare
Bora Eryilmaz
am 14 Dez. 2022
Bearbeitet: Bora Eryilmaz
am 14 Dez. 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.
Siehe auch
Kategorien
Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!