%思想:先预置一个空矩阵,然后把每次循环的结果分别逐个加入这个空矩阵。
% Purpose:Save intermediate variable values for nested loops
% Programmer:YQH
% Date:20181206
clear all;
tic;
lamda1=[0:0.1:1];
lamda2=1-lamda1;
dip1=[70,80,90]; %i
dip2=[70,80,90,100]; % j
kappa1=[20,24,25];
kappa2=[50,59,60,70];
l=length(lamda1);
a=length(dip1);
b=length(dip2);
g=length(kappa1);
h=length(kappa2);
total=labgh;
mil1=[];
result=[]; %预置的空矩阵
file=‘results.mat’;
for i=1:a
for j=1:b
for k=1:g
for m=1:h
for n=1:l
mil1=dip1(i)*dip2(j)*kappa1(k)*kappa2(m)*lamda1(n)*lamda2(n);
result=[result dip1(i) dip2(j) kappa1(k) kappa2(m) mil1 ];
% save(file,‘mil’,’-append’); %可要可不要
end
end
end
end
end
result=result’;
result=reshape(result,5,total);
result=result’;
save(file,‘result’);
toc