simulation help - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


simulation help

fraggle_28fraggle_28 Posts: 2Member

I am trying to generate a stochastic run of 100 simulations and plot the result of each simulation in a histogram. Thus far, I have everything correct except that I can only get 1 simulation each time in my histogram.

Here is my code. Any suggestions for getting all 100 values in it?

n=100; % number of generations to run
x=zeros(1,n+1); %Vector to keep track of time/given generation for potential fixation
t=0:n; % time indices
allele=.5; % Initial frequency of focal alleles
Nlow=2; %Low population size
Nhigh=10; %High population size
mu=[2,10];%Initial distribution
%2 state Markov Chain; Nlow_pop_size to Nhigh_pop_size

x(1)=rando(mu); % generate first x value (time 0, not time 1)

for i=1:n %Cycle through 100 generations

%Generate value based on transition probability Matrix

x(i+1) = rando(P(x(i),);

N=x(i+1);%Variable to keep track of varying population size for each simulation

%Initialize frequency of focal allele to 0.5
thestate=init;%Initial state begins at 0.5
m=0; %Keep track number of times given state is reached
maxgen=100; % Random cutoff for W-F simulation
traj=zeros(1,maxgen);%A useful vector

while (m < maxgen && thestate > 0 && thestate < 2*N)
m=m+1; %Bump counter
%Sample from binomial scheme W-F here
traj(m) = thestate;

if ((thestate==0 || thestate==2*N) && m < maxgen) % fixation has occured: fill the rest of traj with the appropriate value
traj((m+1):maxgen) = repmat(thestate,1,maxgen-m);

end; %if






hist(gencount(i)); My 100 generated values here!

Sign In or Register to comment.