- #1
spoonyluv
- 9
- 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
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