function [n, nospec, evenness] = comm(size,type, par_a,par_b,pool_size,ifplot) % This function generates a community of the size 'size' from an abundance distribution % and returns abundances and number of species %ifplot: 1 linear, 2 logarithmic d=distr(type, par_a,par_b,pool_size); dx=cumsum(d); n = zeros(pool_size,1); for i=1:size r = rand(1); for j=1:pool_size if r0); n1=n(1:nospec); const=sum((log(n1)./nospec)); evenness = 1 - (2 / pi) * atan(sum((log(n1)-const).^2) ./ nospec) if (ifplot == 1) plot(1:pool_size,[d*size;n]); elseif (ifplot == 2) plot(1:pool_size,log([d*size;n])); end if (ifplot) figure('Position',[13*scrsz(4)/20 scrsz(4)/2-30 scrsz(3)/2 scrsz(4)/2-30]); bar(n); title(nospec); end