Compute correlations in 3D arrays
Afficher commentaires plus anciens
%Random matrices
A=randi(100,374,374);
A_ = eye(size(A,[1 2]));
A(ones(size(A))&A_)=NaN;
B=randi(100,374,374);
B_ = eye(size(B,[1 2]));
B(ones(size(B))&B_)=NaN;
The following code computes correlation coeficient and p value from matrices A, B:
nn=374;
temp= ~eye (nn);
ii_all_conn = find(temp>0);
ii_uptri_conn = find(triu(temp,1)> 0);
ii_lotri_conn = find(tril(temp,-1)> 0);
%Corr plots up entries
figure, plot(A(ii_uptri_conn), B(ii_uptri_conn),'o');
[r,p]= corr(A(ii_uptri_conn), B(ii_uptri_conn));
title(['Upper connections - r = ' num2str(r) ' (p ' num2str(p) ')']);
%Corr plots low entries
figure, plot(A(ii_lotri_conn), B(ii_lotri_conn),'o');
[r,p]= corr(A(ii_lotri_conn), B(ii_lotri_conn));
title(['Lower connections - r = ' num2str(r) ' (p ' num2str(p) ')']);
Can I compute the same correlation and p-value in multidimensional arrays? E.g.
A_3D=randi(100,374,374,10);
B_3D=randi(100,374,374,10);
In the output, the first r and p values would correpond to the Pearson coeficient of A(:,:,1), B(:,:,1). and the tenth r and p values correpond to the Pearson coeficient of A(:,:,10), B(:,:,10)
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Linear Algebra dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!