function plotRepetitions ( D ) %plots outcomes of the repetitions %D = zeros ( NReps, MaxTime+1, Npops ); [ nReps maxTime nPops ] = size ( D ); TimePts = 0 : maxTime-1; MaxP = max ( max ( max ( D ) ) ); %plot each repetition - work out the number of subplots f = factor ( nReps ); if length ( f ) == 1 fprintf ( 'Why would you choose a prime number of repetitions?\n' ); nrows = 2; ncols = ceil ( nReps / 2 ); else ncols = f( end ); nrows = prod ( f( 1:end-1 ) ); end figure; for irep = 1 : nReps Dr = squeeze ( D ( irep, :, : ) ); MeanP = mean ( Dr, 2 ); %mean over time subplot ( nrows, ncols, irep ) %choose the subplot for the results plot ( TimePts, Dr ); %plots one line per population hold on %keeps the previous lines on the plot plot ( TimePts, MeanP, 'kx' ); %plots the mean as crosses axis ( [ 0 maxTime-1 0 MaxP ] ); %sets the axis scaling to be equal %this section adds some labels to the subplots on the edges if irep==1; ylabel ( 'Population Size' ); end if irep >= nReps; xlabel ( 'Time' ); end end %plot each repetition - as above, but log axis for population sizes figure for irep = 1 : nReps Dr = squeeze ( D ( irep, :, : ) ); MeanP = mean ( Dr, 2 ); %mean over time subplot ( nrows, ncols, irep ) %choose the subplot for the results semilogy ( TimePts, Dr ); %plots one line per population hold on %keeps the previous lines on the plot semilogy ( TimePts, MeanP, 'kx' ); %plots the mean as crosses axis ( [ 0 maxTime-1 1 MaxP ] ); %sets the axis scaling to be equal %this section adds some labels to the subplots on the edges if irep==1; ylabel ( 'Population Size' ); end if irep >= nReps; xlabel ( 'Time' ); end end