To generate random numbers that follow a normal distribution in MATLAB, you can use the randn
function. However, to specify the mean and standard deviation of the distribution, you would need to have a sample. If you do not have a sample, you can still generate random numbers with a given mean and standard deviation by using the normrnd
function.
The normrnd
function takes two arguments: the mean and standard deviation of the normal distribution. Here's an example code snippet:
main.m241 chars8 lines
This code will generate 100 random numbers with a mean of 0 and a standard deviation of 1, and plot a histogram of the results.
Alternatively, you can use the pdf
function to plot the probability density function of the normal distribution with a given mean and standard deviation:
main.m148 chars4 lines
This code will plot the probability density function of the normal distribution with a mean of 0 and a standard deviation of 1.
gistlibby LogSnag