MATLAB: Poisson Process for 500 variates

distributionpoissonprocess

I would like to generate a code to produce a poisson process for N = 500 variates witk k is randomly between 1 and 10 and lambda = 12.
N = 500;
T = 1;
lambda = 12;
t = linspace(0, T, 100);
dt = t(2) - t(1);
S=cumsum([zeros(1,N); poissrnd(lambda*dt, length(t)-1, N) ]);
plot(t,S)
I generated this code by myself, bu I cannot use the random value of k between 1 and 10 , and 500-variates graph has too many lines, but I guess this result is totally wrong, how can I get rid of my mistakes and write the code properly?
Thanks a lot.
My second code is this
T = 1;
lambda = 12;
k=9;
t = linspace(0, T, 500);
for i = 1:500
f(i) = (lambda.^k) .* exp(-lambda) ./ factorial(k);
end
N = cumsum(f);
disp(N)
stairs(t,N(1:100))
But, again, the graph and estimations are totally wrong.

Best Answer

Hello Zeynep,
You may try this.
lambda = 12;
nPeriods = 500;
dt = 0.1; %time steps
T = nPeriods*dt;
t = 0:0.1:T;
rng('default')
k=randi([1,10],1,nPeriods);
f = (lambda.^k).*exp(-lambda)./factorial(k); % Poission Dist.
Nd = cumsum(f);
N = [ 0 Nd(1:end) ]; % N(0)=0.
stairs(t,N)
If you decrease the Nperiods, you could see the stairs more precisely.