我正在对乘法数据集进行一些统计分析,但似乎真的很难对所有内容进行硬编码,所以我想知道是否有可能为数据集创建一个循环,我的代码是:
dsA = dataset('XLSFile','RING 29 deg.xlsx','Sheet',7);
dsB = dataset('XLSFile','RING 29 deg.xlsx','Sheet',8);
dsC = dataset('XLSFile','RING 29 deg.xlsx','Sheet',9);
dsD = dataset('XLSFile','RING 29 deg.xlsx','Sheet',10);
dsE = dataset('XLSFile','RING 29 deg.xlsx','Sheet',11);
dsX = dataset('XLSFile','RING 29 deg.xlsx','Sheet',12);
dsY = dataset('XLSFile','RING 29 deg.xlsx','Sheet',13);
%Testing differences in median after 0,5 sex for A
[p,t,stats_A_1] = kruskalwallis(dsA.x0_5Sec,dsA.Code_1);
title('Differences in median after 0,5 sec for Concentration A')
print(gcf, '-dpdf', 'A_0,5_sec.pdf');
figure;
[c,m,h,nms] = multcompare(stats_A_1);
title('Differences in median after 0,5 sec for Concentration A')
[nms num2cell(m)]
%Testing differences in median after 1 sex for A
[p,t,stats_A_2] = kruskalwallis(dsA.x1Sec,dsA.Code_1);
title('Differences in median after 1 sec for Concentration A')
print(gcf, '-dpdf', '73_1_sec.pdf');
figure;
[c,m,h,nms] = multcompare(stats_A_2);
title('Differences in median after 1 sec for Concentration A')
[nms num2cell(m)]
%Testing differences in median after 1,5 sex for A
[p,t,stats_A_3] = kruskalwallis(dsA.x1_5Sec,dsA.Code_1);
title('Differences in median after 1,5 sec for Concentration A')
print(gcf, '-dpdf', '73_1,5_sec.pdf');
figure;
[c,m,h,nms] = multcompare(stats_A_3);
title('Differences in median after 1,5 sec for Concentration A')
[nms num2cell(m)]
%Testing differences in median after 2 sex for A
[p,t,stats_A_4] = kruskalwallis(dsA.x2Sec,dsA.Code_1);
title('Differences in median after 2 sec for Concentration A')
print(gcf, '-dpdf', 'A_2_sec.pdf');
figure;
[c,m,h,nms] = multcompare(stats_A_4);
title('Differences in median after 2 sec for Concentration A')
[nms num2cell(m)]
%Testing differences in median after 2,5 sex for A
[p,t,stats_A_5] = kruskalwallis(dsA.x2_5Sec,dsA.Code_1);
title('Differences in median after 2,5 sec for Concentration A')
print(gcf, '-dpdf', 'A_2,5_sec.pdf');
figure;
[c,m,h,nms] = multcompare(stats_A_5);
title('Differences in median after 2,5 sec for Concentration A')
[nms num2cell(m)]
%Testing differences in median after 3 sex for A
[p,t,stats_A_6] = kruskalwallis(dA.x3Sec,dA.Code_1);
title('Differences in median after 3 sec for Concentration A')
print(gcf, '-dpdf', 'A_3_sec.pdf');
figure;
[c,m,h,nms] = multcompare(stats_A_6);
title('Differences in median after 3 sec for Concentration A')
我需要这样做才能将数据集A转换为Y,并且硬编码看起来很愚蠢...但是我试图制作一个循环就像我在处理图像时所做的那样但是我无法使它工作当我尝试使用数据集时,有没有人知道如何做到这一点? 祝你有愉快的一天
答案 0 :(得分:1)
您编写循环时遇到困难,因为您使用的变量名称如stats_A_3
或dsA
,其索引编码为变量名称。要开发循环版本,您必须重构代码并删除此类硬编码索引。从两个"迭代开始"如下所示,修改代码,使迭代之间的所有内容都依赖于变量index
。当您修改代码时,两个块都相同但仍然与以前相同。
%first iteration
index=1
t=index/2
dsA = dataset('XLSFile','RING 29 deg.xlsx','Sheet',7);
%Testing differences in median after 0,5 sex for A
[p,t,stats_A_1] = kruskalwallis(dsA.x0_5Sec,dsA.Code_1);
title('Differences in median after 0,5 sec for Concentration A')
print(gcf, '-dpdf', 'A_0,5_sec.pdf');
figure;
[c,m,h,nms] = multcompare(stats_A_1);
title('Differences in median after 0,5 sec for Concentration A')
[nms num2cell(m)]
%second iteration
index=2
t=index/2
dsB = dataset('XLSFile','RING 29 deg.xlsx','Sheet',8);
%Testing differences in median after 1 sex for A
[p,t,stats_A_2] = kruskalwallis(dsA.x1Sec,dsA.Code_1);
title('Differences in median after 1 sec for Concentration A')
print(gcf, '-dpdf', '73_1_sec.pdf');
figure;
[c,m,h,nms] = multcompare(stats_A_2);
title('Differences in median after 1 sec for Concentration A')
[nms num2cell(m)]
您需要使用的一些工具(如果您不了解,请查看文档):
stats_A_1
替换为stats_A_6
矩阵sprintf
生成您的文件名