n = 100; %number of samples
x = (rand(1,n)-0.5)*8; %uniform random values between -4,4
mu = exp( 1.5 + 0.5*x); %log-linear model for mu
y = poissrnd(mu); %poisson random variables

plot(x,y,'.') %scatter plot
b = glmfit(x,y,'poisson'); %fit poisson model
yhat = glmval(b,x,'log'); %evaluate poisson model

hold on
plot(x,yhat,'.r') % fit to data
hold off

x2 = -4:0.05:4;
yhat2 = glmval(b,x2,'log');

hold on
plot(x2,yhat2,'k')
hold off
