normal distribution without a sample in matlab

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.m
mu = 0; % mean of the distribution
sigma = 1; % standard deviation of the distribution
n = 100; % number of random numbers to generate

r = normrnd(mu,sigma,n,1); % generate n random numbers

hist(r) % plot a histogram of the random numbers
241 chars
8 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.m
x = -5:0.1:5; % range of x values to plot
y = normpdf(x,mu,sigma); % probability density function
plot(x,y) % plot the probability density function
148 chars
4 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