How to Prevent n From Going Below 0

2 visualizaciones (últimos 30 días)
Gregory Shoemake
Gregory Shoemake el 28 de Nov. de 2016
Comentada: Gregory Shoemake el 28 de Nov. de 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!

Respuesta aceptada

KSSV
KSSV el 28 de Nov. de 2016
use break if the value of n is 0.

Más respuestas (0)

Categorías

Más información sobre Encryption / Cryptography en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by