从来没有一个好的理由来创建动态变量名。他们制造的问题之一就是你所经历的。使用structs/cell arrays/nd arrays;视情况而定。在您的情况下,struct似乎更适合如下所示:
%Converting your data matrices into a struct
Diff_ = struct('CT',Diff_CT, 'Imp',Diff_Imp, 'F1',Diff_F1, 'F2', Diff_F2);
for i_parameters = 1 : numel(parameters)
my_parameters = parameters{i_parameters};
%Creating structures with your variables as their fields
Diff_.([my_parameters '_T0']) = [Diff_.(my_parameters)(:,1) ...
Diff_.(my_parameters)(:,8) Diff_.(my_parameters)(:,15) ...
Diff_.(my_parameters)(:,22) Diff_.(my_parameters)(:,29)];
DiffMean.([my_parameters '0']) = mean(mean(Diff_T0.(my_parameters)));
Diffstd.([my_parameters '0']) = std(std(Diff_T0.(my_parameters)));
end
你期望的变量是什么
Diff_CT_T0
,
DiffMeanCT0
和
DiffstdCT0
现在可以作为
Diff_.CT_T0
,
DiffMean.CT0
和
Diffstd.CT0
分别等等。