by An Uncommon Lab


Draws samples from a probability mass function defined by an array of discrete probabilities.

indices = pmfdraw(p)
indices = pmfdraw(p, n)



Array defining a probability mass function


Number of draws to make (defaults to the length of p)



Random draws corresponding to indicies of p


We'll create a 3-element probability distribution, where the first element occurs 25% of the time, the second element occurs 40% of the time, and the third element occurs 35% of the time.

p = [0.25 0.4 0.35];

We can make 1000 random draws from this distribution. Approximately 25% will be 1, 40% will be 2, and 35% will be 3.

indices = pmfdraw(p, 1000);

Let's see how we did:

sum(indices == 1)/1000
sum(indices == 2)/1000
sum(indices == 3)/1000
ans =
ans =
ans =

Particle filters use discrete probabilities as "weights" for each particle, so that particles that produce predictions of the observation that are consistent with the true measurement end up with a higher probability. These most-likely particles are more likely to be selected during resampling, resulting in a clustering of particles near high-probability areas of the state space. This function is useful to randomly draw the particles to select according to their individual "probabilities".

See Also

bf, mnddraw

Table of Contents

  1. Inputs
  2. Outputs
  3. Example