I want generate a number in Gaussian and Uniform distributions in matlab.
I know this function randi
and rand()
but all of them are in normal (Gaussian) distribution. How can a generate a random number in uniform distribution?
r = normrnd( mu , sigma ) generates a random number from the normal distribution with mean parameter mu and standard deviation parameter sigma . r = normrnd( mu , sigma , sz1,...,szN ) generates an array of normal random numbers, where sz1,...,szN indicates the size of each dimension.
X = rand( sz ) returns an array of random numbers where size vector sz defines size(X) . For example, rand([3 4]) returns a 3-by-4 matrix. X = rand(___, typename ) returns an array of random numbers of data type typename . The typename input can be either "single" or "double" .
The inversion method relies on the principle that continuous cumulative distribution functions (cdfs) range uniformly over the open interval (0,1). If u is a uniform random number on (0,1), then x = F - 1 ( u ) generates a random number x from any continuous distribution with the specified cdf F .
Use rand(dimensions)
for a Uniform Distribution between 0 and 1.
Use randn(dimensions) * sqrt(sigma) + mu
for a Gaussian Distribution with a mean of mu and standard deviation of sigma.
randn
is the function to generate Gaussian distributed variables (randi
and rand
produce uniformly distributed ones).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With