Simulating 100-Day Experiments with an Index Case

  • Context: MATLAB 
  • Thread starter Thread starter spoonyluv
  • Start date Start date
  • Tags Tags
    Experiments Index
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
2 replies · 2K views
spoonyluv
Messages
9
Reaction score
0
Hello,

Here is my scenario: I am trying to run a code a 100 times, so I use a for loop statement i=1:100. The 1 to 100 stands for 1 to 100 days. Now I want to see how much randomness my results give and so I want to simulate this whole 100 days thing twice.

So I think my code would look something like this:

for m = 1:2
for i = 1:100

do something something

end
end

However here is the problem: within the code, do something something, i have this person that I have infected...I call him index case and initially assign him a value of 1 and within the period of 100 days I recover him and assign him a value of 2. so great. so the code works great from a period of 1-100. however when m=2 starts, I want the index case to go back to 1, and start the 100 day simulation again and I can't figure the best way to do that. The only thing I can think of is writing, towards the end, is when j > 100, index = 2, but I know that isn't right because Matlab will just ignore that part of the code since j never goes to greater than 100.

How do I get around this?

Thanks
 
Physics news on Phys.org
Just put index = 2 after the first loop
Code:
index=1;
for m = 1:2
     for i = 1:100

     do something something

     end
     index=2;
end
 
Or, instead of writing "for m=1:2", write "for index=1:2" and this should take care of everything