【发布时间】:2012-01-16 12:02:09
【问题描述】:
如果您运行以下代码,您最终会得到一个元胞数组,该元胞数组由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 中是否可行?
【问题讨论】:
-
似乎是您之前的@987654322@ 的重复。您没有得到好的答案可能是因为您的问题不清楚,并且您的代码示例比应有的复杂。
-
看不明白,代码只是一个示例代码,只是产生一个结果,代码的结构无关紧要。只是询问是否有可能从结果“CovMatrix”到链接中显示的表格。复杂吗?
标签: matlab correlation