How to Prevent n From Going Below 0
2 views (last 30 days)
Show older comments
Gregory Shoemake
on 28 Nov 2016
Commented: Gregory Shoemake
on 28 Nov 2016
So I had to write a script that simulated bacteria growth over a certain number of generations. I've got it all working expect for the fact that I want the program to end if the population drops below 0, as an extinct population can hardly come back suddenly or continue to lose members. Here's the coding, how can I end the program in this situation?
g = input('Number of Generations: ');
n = 1;
p = rand(g);
for a = 1:g
if p(a) >= 0.5
n = n + 1;
elseif p(a) < 0.5
n = n - 1;
elseif n == 0
return;
end
end
n
Thank you!
0 Comments
Accepted Answer
More Answers (0)
See Also
Categories
Find more on Encryption / Cryptography 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!