correlation pairs
Afficher commentaires plus anciens
The following code calculates the correlation between 2 vectors:
clear all
%generate fake data
LName={'Name1','Name2','Name3'};
Data={rand(12,1),rand(12,1),rand(12,1)};
%place in a structure
d = [LName;Data];
Data = struct(d{:});
%find the correlation
SNames=fieldnames(Data);
pairs = combnk (1:numel(SNames),2);
for i = 1 : size (pairs,1)
[R{i},P{i}] = corrcoef(Data.(SNames{pairs(i,1)}),Data.(SNames{pairs(i,2)}));
Correlation{i}=R{i}(1,2);
end
However, I want to find the correlation between all possible combinations. So, not just calculate the correlation between 2 elements but between 2 and then between 3... and so on. I can find the correlation between 3 elements by changing the line:
pairs = combnk (1:numel(SNames),3);
to
for i = 1:length(fieldnames(Data));
pairs.(SNames{i,1}) = combnk (1:numel(SNames),i);
end
But I want to adapt this to not just list the names from 'SNames' but to write which combinations i.e. SName1 v SName2.
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Correlation and Convolution 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!