Main Content

poissrnd

Random numbers from Poisson distribution

Description

example

r = poissrnd(lambda) generates random numbers from the Poisson distribution specified by the rate parameter lambda.

lambda can be a scalar, vector, matrix, or multidimensional array.

example

r = poissrnd(lambda,sz1,...,szN) generates an array of random numbers from the Poisson distribution with the scalar rate parameter lambda, where sz1,...,szN indicates the size of each dimension.

example

r = poissrnd(lambda,sz) generates an array of random numbers from the Poisson distribution with the scalar rate parameter lambda, where vector sz specifies size(r).

Examples

collapse all

Generate an array of random numbers from the Poisson distributions. Specify the average rate for each distribution.

lambda = 10:2:20
lambda = 1×6

    10    12    14    16    18    20

Generate random numbers from the Poisson distributions.

r = poissrnd(lambda)
r = 1×6

    14    13    14     9    14    31

Generate an array of random numbers from one Poisson distribution. Here, the distribution parameter lambda is a scalar.

Use the poissrnd function to generate random numbers from the Poisson distribution with the average rate 20. The function returns one number.

r_scalar = poissrnd(20)
r_scalar = 9

Generate a 2-by-3 array of random numbers from the same distribution by specifying the required array dimensions.

r_array = poissrnd(20,2,3)
r_array = 2×3

    13    14    18
    26    16    21

Alternatively, specify the required array dimensions as a vector.

r_array = poissrnd(20,[2 3])
r_array = 2×3

    22    27    22
    25    19    21

Input Arguments

collapse all

Rate parameters, specified as a positive value or array of positive values. The rate parameter indicates the average number of events in a given time interval.

Example: 2

Data Types: single | double

Size of each dimension, specified as separate arguments of integers. For example, specifying 5,3,2 generates a 5-by-3-by-2 array of random numbers from the Poisson probability distribution.

If lambda is an array, then the specified dimensions sz1,...,szN must match the dimensions of lambda.

  • If you specify a single value sz1, then r is a square matrix of size sz1-by-sz1.

  • If the size of any dimension is 0 or negative, then r is an empty array.

  • Beyond the second dimension, poissrnd ignores trailing dimensions with a size of 1. For example, poissrnd(5,3,1,1,1) produces a 3-by-1 vector of random numbers from the Poisson distribution with rate parameter 5.

Example: 5,3,2

Data Types: single | double

Size of each dimension, specified as a row vector of integers. For example, specifying [5 3 2] generates a 5-by-3-by-2 array of random numbers from the Poisson probability distribution.

If lambda is an array, then the specified dimensions sz must match the dimensions of lambda.

  • If you specify a single value [sz1], then r is a square matrix of size sz1-by-sz1.

  • If the size of any dimension is 0 or negative, then r is an empty array.

  • Beyond the second dimension, poissrnd ignores trailing dimensions with a size of 1. For example, poissrnd(5,[3,1,1,1]) produces a 3-by-1 vector of random numbers from the Poisson distribution with rate parameter 5.

Example: [5 3 2]

Data Types: single | double

Output Arguments

collapse all

Random numbers from the Poisson distribution, returned as a scalar value or an array of scalar values.

Data Types: single | double

Alternative Functionality

  • poissrnd is a function specific to Poisson distribution. Statistics and Machine Learning Toolbox™ also offers the generic function random, which supports various probability distributions. To use random, specify the probability distribution name and its parameters. Alternatively, create a PoissonDistribution probability distribution object and pass the object as an input argument. Note that the distribution-specific function poissrnd is faster than the generic function random.

  • To generate random numbers interactively, use randtool, a user interface for random number generation.

Extended Capabilities

Version History

Introduced before R2006a