相关值表

发布于 2024-12-27 01:17:11 字数 1607 浏览 1 评论 0原文

如果运行以下代码,您最终将得到一个元胞数组,该元胞数组由 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 中可行吗?

If you run the following code you will end up with a cell array composed of a correlation value in CovMatrix(:,3) and the name of the data used in calculating the correlation in CovMatrix(:,1) and 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 

From this I need to produce a table of the values, preferably in the form of a correlation matrix, similar to jeremytheadventurer.blogspot.com. Would this be possible in MATLAB?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

献世佛 2025-01-03 01:17:11

您可以使用 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 是对称的,因此如果您忽略上面的矩阵,则它包含所需的结果三角形部分。

You can compute the correlation matrix of your entire data set in one shot using corrcoef command:

% 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}

Because the correlation matrix CovMat is symmetric, this contains the required result if you ignore the upper triangular part.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文