How to save each iteration of nested for loops?
1 view (last 30 days)
Show older comments
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
0 Comments
Accepted Answer
Stalin Samuel
on 6 Dec 2014
ErrRMSE(step1,step2,step3,step4,step5) = sqrt(sum((Difference).^2)/1099);
0 Comments
More Answers (0)
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!