Documentation

unifrnd

Continuous uniform random numbers

Syntax

R = unifrnd(A,B)
R = unifrnd(A,B,m,n,...)
R = unifrnd(A,B,[m,n,...])

Description

R = unifrnd(A,B)returns an arrayRof random numbers generated from the continuous uniform distributions with lower and upper endpoints specified byAandB, respectively. IfAandBare arrays,R(i,j)is generated from the distribution specified by the corresponding elements ofAandB. If eitherAorBis a scalar, it is expanded to the size of the other input.

R = unifrnd(A,B,m,n,...)orR = unifrnd(A,B,[m,n,...])returns anm-by-n-by-... array. IfAandBare scalars, all elements ofRare generated from the same distribution. If eitherAorBis an array, they must bem-by-n-by-... .

Examples

生成一个随机数each from the continuous uniform distributions on the intervals (0,1), (0,2), ..., (0,5):

a = 0; b = 1:5; r1 = unifrnd(a,b) r1 = 0.8147 1.8116 0.3810 3.6535 3.1618

Generate five random numbers each from the same distributions:

B = repmat(b,5,1); R = unifrnd(a,B) R = 0.0975 0.3152 0.4257 2.6230 3.7887 0.2785 1.9412 1.2653 0.1428 3.7157 0.5469 1.9143 2.7472 3.3965 1.9611 0.9575 0.9708 2.3766 3.7360 3.2774 0.9649 1.6006 2.8785 2.7149 0.8559

Generate five random numbers from the continuous uniform distribution on (0,2):

r2 = unifrnd(a,b(2),1,5) r2 = 1.4121 0.0637 0.5538 0.0923 0.1943

Extended Capabilities

Introduced before R2006a

Was this topic helpful?