How to generate random number from cumulative distribution function (CDF) in Matlab
49 views (last 30 days)
Similar to R program, I'm looking for a code in Matlab that I can generate a set of random number with a specific mean (M) and standard deviation (sd).
R code to generate random number with normal distribution from CDF:
> pnorm(1.96, mean=0, sd=1)
More Answers (2)
Did you see the example in the help for randn()? Here it is:
Random Numbers from Normal Distribution with Specific Mean and Variance
This example shows how to create an array of
random floating-point numbers that are drawn
from a normal distribution having a mean of 500 and variance of 25.
The randn function returns a sample of random numbers from a normal distribution
with mean 0 and variance 1. The general theory of random variables
states that if x is a random variable whose mean is μ
and variance is σ
, then the random variable, y, defined by y=ax+b,
where a and b are constants, has mean μ
+b and variance σ
. You can apply this concept to get a sample of
normally distributed random numbers with mean 500 and variance 25.
First, initialize the random number generator to make the results in this example repeatable.
Create a vector of 1000 random values
drawn from a normal distribution with a mean of 500
and a standard deviation of 5.
a = 5;
b = 500;
y = a.*randn(1000,1) + b;