How to save each iteration of nested for loops?

1 次查看(过去 30 天)
I have a function with 5 parameters. I am trying to run the function varying each parameter within their given ranges. I need to find the error associated with each combination of the 5 parameters so I need to save the error for each iteration. Currently, it overwrites it, leaving me with only the last value. Thank you for your help!
Code:
% CMAX b ALPHA Ks Kq
MinB = [1.0 0 0 .0002 .1]; % minimum boundary
MaxB = [1000 2.0 1 .10 .99]; % maximum boundary
resolution = 3;
pcmax = (1: ((1000-1)/resolution): 1000);
pb = (0: ((2-0)/resolution): 2);
palpha = (0: ((1-0)/resolution): 1);
pks = (.0002: ((.1-.0002)/resolution): .10);
pkq = (.1: ((.99-.1)/resolution): .99);
Pars = zeros(3,3,3,3,3);
for step1=1:4
for step2=1:4
for step3=1:4
for step4=1:4
for step5=1:4
Pars = [pcmax(step1) pb(step2) palpha(step3) pks(step4) pkq(step5)];
[SimFlow] = HyMod(Pars,PET,Precip); % Run model
Difference = abs(ObsFlow - SimFlow);
ErrRMSE = sqrt(sum((Difference).^2)/1099);
end
end
end
end
end

采纳的回答

Stalin Samuel
Stalin Samuel 2014-12-6
ErrRMSE(step1,step2,step3,step4,step5) = sqrt(sum((Difference).^2)/1099);

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by