I want to generate a Poisson distributed vector of random numbers, without any of the numbers being 0. The code I have is(adsbygoogle = window.adsbygoogle || []).push({});

k = poissrnd(kmean,1,N);

% where kmean is the mean of the distribution, and has been defined previously

%The above generates a N by 1 vector of Poisson distributed random numbers, with mean and variance kmean. N has also been defined previously.

%poissrnd is a command in newer versions of MATLAB

for i = 1:N

while k(i) == 0

k = poissrnd(kmean,1,N);

end

end

So basically if the vector of random numbers contains a 0, I want to redraw the vector.

The code doesn't work, and I can't seem to make it work. Can someone please give me some advice?

Thanks a lot!!

**Physics Forums - The Fusion of Science and Community**

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# While and for loops in MATLAB

Can you offer guidance or do you also need help?

Draft saved
Draft deleted

Loading...

Similar Threads - While loops MATLAB | Date |
---|---|

Mathematica While Loop in Mathematica | Feb 25, 2018 |

Matlab What is wrong with this WHILE loop? | Aug 26, 2016 |

Finding quotient using while loop | Jun 15, 2012 |

How to plot multiple iterations of a while loop on one plot? [MATLAB] | Oct 6, 2011 |

Building a matrix using while loops? (MATLAB) | Feb 8, 2010 |

**Physics Forums - The Fusion of Science and Community**