Hi All,
I'm running a population model in Matlab (using an mfile) and Im calculating populations due to certain external conditions using a few for loops. Anyway, if the population reaches 25000 the species will collapse (i.e. become extinct no matter how the external conditions change), and I want my for loop to stop if that population reaches 25000 or less, but I dont know how.
Here is my code:
rainarray = [100,38,100,104, 167,167,165,79,91,77,134,192,235,159,211,257,204,3 00,187.84,99,163,97,228,208,83,44,99,163,97,228,20 8,83,44,112,191,202,137,150,158,20];
R = 1.1323;
n0=200000; % Defines the initial population as 200,000
n = zeros(1,100); % Preallocates space
t=1:100; % Sets time intervals i.e. every year for 100 years
h=0.2
for i = 2:100
z= randperm(numel(rainarray)); % Generates random arrangement of indices of rainarray
rain = rainarray(z(1:1)); % Selects one random rainfall figure from rainarray
K = 5532*rain; % Defines the Carrying Capacity
n(:,1) = n0; % Sets the initial population as n0 (see above)
n(:,i) = (R*n(:, i-1)*K)/(K+(R-1)*n(:,i-1))*(1-h); % Beverton-Holt model for a loop with harvest rate
if n(:,i) <= 25000 % Sets lower threshold
THIS IS WHERE I NEED SOME CODE SO THE FOR LOOP (i.e. for i = 2:100) COMPLETELY STOPS AND DOESN"T KEEP CALCULATING THE OTHER
POPULATION LEVELS
end
figure(1)
plot(t,n,'b');
end
Does anyone know such a command to end that loop at that point when n becomes <= 25000?
Thanks in advance for any help


LinkBack URL
About LinkBacks
