matlab里 for 四阶循环 如何保存每一次运行的参数值和结果?

2025-04-03 11:27:02
推荐回答(2个)
回答1:

global b1 a1 a2 a3;
co_b1 = 0.01:0.05:0.2;
co_a1 = 0.01:0.05:0.2;
co_a2 = 1.5:0.2:3;
co_a3 = 0.5:0.1:1.0;
%allanswer 存放所有结果
allanswer=[];
for k = 1:length(co_b1)
for l = 1:length(co_a1)
for m = 1:length(co_a2)
for n = 1:length(co_a3)
b1 = co_b1(k);
a1 = co_a1(l);
a2 = co_a2(m);
a3 = co_a3(n);
run('C:\MATLABWork\SDMCT\ModelTest.m')
cell{k,:,:,:} = b1;
cell{:,l,:,:} = a1;
cell{:,:,m,:} = a2;
cell{:,:,:,n} = a3;
cell{k,l,m,n} = snr;

%存放结果
allanswer=[allanswer;b1 a1 a2 a3 snr];
end
end
end
end

回答2:

新建一个四阶数组,每次都保存可以吗?