help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

## mutate=rand([size(newpop,1)1]) < q this looks right but I keep getting

 From: naryana.shankara Subject: mutate=rand([size(newpop,1)1]) < q this looks right but I keep getting a parse error Date: Tue, 8 Mar 2016 18:24:17 -0800 (PST)

```Usually when I get an error its something stupid like mismatched brackets or
wrong punctuation.
I getting a parse error here is my code (offending line between spaces and
>>> >>>>:
%N= number of sites
%B=number of breeders
%p=migration propensity
%q=probability of mutation occuring
%b=offspring
%m=movement
function [xmean, n, xstd, occupied] = dispersal(N,B,p,q,b,m)
pop=[rand([N 1]) (1:N)'];
for t=1:1000
xmean(t) = mean(pop(:,1));
xstd(t) = std(pop(:,1));
n(t) = length(pop(:,1));
if t/20==floor(t/20)
figure(1); %generate new plot every 20th iteration
subplot(2,1,1);plot(1:t,xmean);
ylabel('Mean Dispersal Rate');
title (['Mortality=' num2str(m)]);
subplot(2,1,1);plot(1:t,n);
xlabel('Time');
ylabel('Population Size');
drawnow;
end
%randomize number of idividuals using randperm
ind=randperm(size(pop,1)); %use onlt the first column
pop=pop(ind,:); %reorder population by the random number generated above
disaster =find(rand([N 1])<p); %destroy some sites if number &lt; p then
use it in disasterplaces
disasterplaces=intersect(pop(:,2),disaster); %intersect the array (2nd
column) and disaster
for i =1:length(disasterplaces) %kill residents of disasterplaces
f=find(pop(:,2)==disasterplaces(i));
pop(f,:)=[];
end;
for i=1:N %competition among the living between 1 and N
potentialbreeders=find(pop(:,2)==i);
if length(potentialbreeders)>B %remover the excess breeders
pop(potentialbreeders(B+1:end),:)=[];
end;
end;
occupied(t)=length(unique(pop(:,2)))/N;
if size(pop)==0 break; %break loop when population becomes extinct
end;
newpop=[]; %collect offspring
for i = 1:b %loop between 1 and b-offspring
newpop=[newpop; pop];
end;

>>>>mutate=rand([size(newpop,1)1]) < q %probability of mutation occuring use
1st column when no mutation occur>>>>>>>>>>>>>>>

newpop(:,1)=newpop(;,1).*(~mutate)+rand([size(newpop,1)1]).*mutate;
%mutate
might be an unequal array use ~
move=rand([size(newpop,1),1])< newpop(:,1)
newlocation=ceil(N*rand([size(newpop,1)1]));
newpop(:,2)=(newpop(:,2).*(~move)+newlocation.*move %use 2nd column of
newpop remains same if no movement else use predefined location
death=find((rand([size(newpop,1)1])<m).*move); %death to movements
newpop(death,:)=[];
pop=newpop;
end;

thanks

--
View this message in context:
http://octave.1599824.n4.nabble.com/mutate-rand-size-newpop-1-1-q-this-looks-right-but-I-keep-getting-a-parse-error-tp4675304.html
Sent from the Octave - General mailing list archive at Nabble.com.

```

reply via email to

 [Prev in Thread] Current Thread [Next in Thread]