Таблица значений корреляции - PullRequest
1 голос
/ 16 января 2012

Если вы выполните следующий код, вы получите массив ячеек, состоящий из значения корреляции в CovMatrix(:,3) и имени данных, используемых для вычисления корреляции в CovMatrix(:,1) и CovMatrix(:,2):

clear all
FieldName = {'Name1','Name2','Name3','Name4','Name5'};
Data={rand(12,1),rand(12,1),rand(12,1),rand(12,1),rand(12,1)};
DataCell = [FieldName;Data];%place in a structure - this is the same
%structure that the data for the lakes will be placed in.
DataStructure = struct(DataCell{:});
FieldName = fieldnames(DataStructure); 
Combinations = nchoosek (1:numel(FieldName),2);
d1 = cell2mat(struct2cell(DataStructure)');%this will be the surface temperatures
%use the combinations found in 'Combinations' to define which elements to
%use in calculating the coherence.
R = cell(1,size(Combinations,1));%pre-allocate the cell array
Names1 = cell(1,size(Combinations,1));
for j = 1:size(Combinations,1);
    [R{j},P{j}] = corrcoef([d1(:,[Combinations(j,1)]),d1(:,[Combinations(j,2)])]);
    Names1{j} = ([FieldName([Combinations(j,1)],1),FieldName([Combinations(j,2)],1)]);
end
%only obtain a single value for the correlation and p-value
for i = 1:size(Combinations,1);
    R{1,i} = R{1,i}(1,2);
    P{1,i} = P{1,i}(1,2);
end
R = R';P = P';
%COVARIANCE MATRIX
CovMatrix=cell(size(Combinations,1),3);%pre-allocate memory
 for i=1:size(Combinations,1);
     CovMatrix{i,3}=R{i,1};
     CovMatrix{i,1}=Names1{1,i}{1,1};
     CovMatrix{i,2}=Names1{1,i}{1,2};
 end 

Из этого мне нужно составить таблицу значений, предпочтительно в форме корреляционной матрицы, аналогичной jeremytheadventurer.blogspot.com . Будет ли это возможно в MATLAB?

1 Ответ

0 голосов
/ 16 января 2012

Вы можете вычислить матрицу корреляции всего набора данных за один снимок, используя команду corrcoef:

% d1 can be simply computed as
d1_new = cell2mat(Data);

% Make sure that d1_new is the same matrix as d1
max(abs(d1(:)-d1_new(:)))

% Compute correlation matrix of columns of data in d1_new in one shot
CovMat = corrcoef(d1_new)

% Make sure that entries in CovMat are equivalent to the third column of
% CovMatrix, e.g.
CovMat(1,2)-CovMatrix{1,3}
CovMat(1,4)-CovMatrix{3,3}
CovMat(3,4)-CovMatrix{8,3}
CovMat(4,5)-CovMatrix{10,3}

Поскольку матрица корреляции CovMat симметрична, она содержит требуемый результат, если игнорировать верхнюю треугольную часть.

...