Help with running a Monte Carlo please...and another question :)
Show older comments
Hi there,
My code is broken up into the following segments:
Lines 7-54 : import data and preallocate for later matrices
Lines 61-148 : a bunch of variables that will be subject to a Monte Carlo simulations (normal distribution)
Lines 155 - 327 : a bunch of for-loops used to define the parameters used in the equation on Line 338.
Lines 328 and on are where I'm having difficulty... There are two issues.
1st: I'm asking the code to run the equation on L342 at sucessively later and later startpoints until the modeled serum level an the end of simulation no longer exceeds that of the measured serum. Once that is met, I'd like to save what that start time was of the last iteration (I took a stab at this on L350, but it's not working...). It should be noted that each column is a seperate person's data and each row is a 1 year time interval. So for example, in the first iteration, the model starts at 1970, if Serum(98,column) is greater than Serum_blood(column), then the simulation starts over at 1971, if it is still greater than in that iteration, run the model again starting at 1972, and so on. Ultimatly, I'm trying to, in a sense, back calculate the start of exposure to a contaminant. So, that is why I'm trying to determine/save the final start point for each participant (column). Hopefully this makes sense.
2nd: (and thank you for still giving this quandry the time of day/night!!) I want to run the monte carlo 1000 times.... so that I'm able to come up with a range and distribution of possible exposure start times per person. Do I nest the bulk of the code (L63-end) in a master for-loop? How would I index this and also, how would I save the output so I'm not overwriting previous monte carlo iteration results?
Thank you for any insights!!!!!! They are appreciated.
1 Comment
darova
on 13 Mar 2021
This part of the code can be simpler
if Water(t,column) == 1
Consumed(t,column) = Cons1;
else
if Water(t,column) == 2
Consumed(t,column)= Cons2;
else
if Water(t,column) == 3
Consumed(t,column)= Cons3;
else
if Water(t,column) == 4
Consumed(t,column)= Cons4;
else
if Water(t,column) == 5
Consumed(t,column)= Cons5;
else
if Water(t,column) == 6
Consumed(t,column)= Cons6;
else
if Water(t,column) == 7
Consumed(t,column) = Cons7;
else
if Water(t,column) == 8
Consumed(t,column) = Cons8;
else
Consumed(t,column)= Cons9;
end
end
end
end
end
end
end
end
end
Just use arrays
cons = [ 1 2 3 4 ... % some data ]
COnsumed(t,column) = cons(Water(t,column));
Accepted Answer
More Answers (0)
Categories
Find more on Matrix Indexing 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!