How do I loop on multiple indicies?
Show older comments
I have the following code that performs the calculation, but I need to repeat that calculation for about 100 sets of input values. Specifically, I need to vary the values for paro, mmhgo, flowrate, sechii, and transit. I can use a for loop for one of the variables, but I do not know how to code for changing them all simultaneously. I imagine that the code could read one line (row) of input data from a file with each field (column) corresponding to one of my variables just mentioned. In other words, for one set of calculations the inputs would be paro=44.3, mmgho=0.022, flowrate=1.7e7, sechii=45, and transit=5. For another run, paro=49.27, mmhgo=0.09, flowrate=5.69e10, sechii=76, and transit=23. Any suggestions on how to do this are much appreciated.
mixingconst=4; %number of times in one day that a day's volume of water is homogenized
sechii=76; %in cm
flowrate=1.70E+10; %Flow rate in L day-1
paro=49.29; %surface mean monthly PAR value mol m-2 day-1
mmhgo=[0.09,0.022]; %initial MMHg concentration in ng L-1
transit=14*mixingconst; %transit days * the number of mixing times each day
kz=(1.44/(sechii/100))/10; %puts kz into units of 0.1 m-1
kd=0.011; %mean value from incubation experiments
depth=70; %this I hold constant
z = 1:depth; %each layer is 0.1 m
parz = paro*exp(-kz*z); %light penetration equation
layerconst=exp(-kd*parz); %the loss fraction at each layer
mulconstant = sum(layerconst) / depth; %the loss fraction for the whole water column
mmhgnew = mmhgo * cumprod(repmat(mulconstant, 1, transit)); %the progression of water column concentrations (cumulative product).
mmhgmnew=mmhgnew*(flowrate/1e9); %the progression of water column mass (cumulative product)
mmhgmo=mmhgo*(flowrate/1e9); %water column mass on day 0
mmhgmloss=mmhgmo-mmhgmnew(transit) %cumulative mass lost
Accepted Answer
More Answers (0)
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!