exprnd - Exponential random numbers - MATLAB
Exponential random numbers
Syntax
Description
generates an array of random numbers from the exponential distribution, where
r = exprnd(mu,sz1,...,szN)sz1,...,szN indicates the size of each dimension.
Examples
collapse all
Generate a single random number from the exponential distribution with mean 5.
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, thenris a square matrix of sizesz1-by-sz1.If the size of any dimension is
0or negative, thenris an empty array.Beyond the second dimension,
exprndignores 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], thenris a square matrix of sizesz1-by-sz1.If the size of any dimension is
0or negative, thenris an empty array.Beyond the second dimension,
exprndignores 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
exprndis a function specific to the exponential distribution. Statistics and Machine Learning Toolbox™ also offers the generic functionrandom, which supports various probability distributions. To userandom, create anExponentialDistributionprobability distribution object and pass the object as an input argument or specify the probability distribution name and its parameters. Note that the distribution-specific functionexprndis faster than the generic functionrandom.To generate random numbers interactively, use
randtool, a user interface for random number generation.
Extended Capabilities
expand all
Usage notes and limitations:
The generated code can return a different sequence of numbers from the sequence returned by MATLAB® if either of the following is true:
The output is nonscalar.
An input parameter is invalid for the distribution.
For more information on code generation, see Introduction to Code Generation and General Code Generation Workflow.
Version History
Introduced before R2006a