Main Content

exprnd

Exponential random numbers

Description

example

r = exprnd(mu) generates a random number from the exponential distribution with mean mu.

example

r = exprnd(mu,sz1,...,szN) generates an array of random numbers from the exponential distribution, where sz1,...,szN indicates the size of each dimension.

example

r = exprnd(mu,sz) generates an array of random numbers from the exponential distribution, where vector sz specifies size(r).

Examples

collapse all

Generate a single random number from the exponential distribution with mean 5.

r = exprnd(5)
r = 1.0245

Generate a 1-by-6 array of exponential random numbers with unit mean.

mu1 = ones(1,6); % 1-by-6 array of ones
r1 = exprnd(mu1)
r1 = 1×6

    0.2049    0.0989    2.0637    0.0906    0.4583    2.3275

By default, exprnd generates an array that is the same size as mu.

If you specify mu as a scalar, then exprnd expands it into a constant array with dimensions specified by sz1,...,szn.

Generate a 2-by-6 array of exponential random numbers with mean 3.

mu2 = 3;
sz1 = 2;
sz2 = 6;
r2 = exprnd(mu2,sz1,sz2)
r2 = 2×6

    3.8350    0.1303    5.5428    0.1313    0.6684    2.5899
    1.8106    0.1072    0.0895    2.1685    5.8582    0.2641

If you specify both mu and sz1,...,szn as arrays, then the dimensions specified by sz1,...,szn must match the dimension of mu.

Generate a 1-by-6 array of exponential random numbers with means 5 through 10.

mu3 = 5:10;
sz = [1 6];
r3 = exprnd(mu3,sz)
r3 = 1×6

    1.1647    0.2481    2.9539   26.6582    1.4719    0.6829

Input Arguments

collapse all

Mean of the exponential distribution, specified as a positive scalar value or an array of positive scalar values.

To generate random numbers from multiple distributions, specify mu using an array. Each element in r is the random number generated from the distribution specified by the corresponding element in mu.

Example: [1 2 3 5]

Data Types: single | double

Size of each dimension, specified as separate arguments of integers.

If mu is an array, then the specified dimensions sz1,...,szN must match the dimensions of mu. The default values of sz1,...,szN are the dimensions of mu.

  • 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, exprnd ignores trailing dimensions with a size of 1. For example, exprnd(4,3,1,1,1) produces a 3-by-1 vector of random numbers from the distribution with mean 4.

Example: 2,4

Data Types: single | double

Size of each dimension, specified as a row vector of integers.

If mu is an array, then the specified dimensions sz must match the dimensions of mu. The default values of sz are the dimensions of mu.

  • 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, exprnd ignores trailing dimensions with a size of 1. For example, exprnd(4,[3 1 1 1]) produces a 3-by-1 vector of random numbers from the distribution with mean 4.

Example: [2 4]

Data Types: single | double

Output Arguments

collapse all

Exponential random numbers, returned as a nonnegative scalar value or an array of nonnegative scalar values with the dimensions specified by sz1,...,szN or sz. Each element in r is the random number generated from the distribution specified by the corresponding element in mu.

Alternative Functionality

  • exprnd is a function specific to the exponential distribution. Statistics and Machine Learning Toolbox™ also offers the generic function random, which supports various probability distributions. To use random, create an ExponentialDistribution probability distribution object and pass the object as an input argument or specify the probability distribution name and its parameters. Note that the distribution-specific function exprnd 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