Experiment noise data (mnoise) which follow a normal distribution with mean 0 and standard deviation of 0.024

I am generating 251 experiment noise data (mnoise) which follow a normal distribution with mean 0 and standard deviation of 0.024. And I have to use 'rand' command.
I know how to generate random numbers using rand command. But I don't know how to generate noise data that follows mean=0.5 and sd=0.024. I have been using
Y = normpdf(X,mu,sigma) function.
I also know that normal distribution is a bell shape plot that is based on mean and sd. Please help. Any tips would be very helpful.

 Réponse acceptée

Are you sure you have to use the rand() command and not the randn() function?
normpdf() is not for generating random numbers. You can generate data that follows the N(0.5,0.024^2) distribution with
x = 0.5+0.024*randn(251,1);

2 commentaires

Hi Wayne, Thanks so much for pointing out. I have been solving this problem for almost 2 days. Yes, it is meant to be "randn()function". Thanks million. I will give it a try now.
Hi wayne, I found the below program in one of the forum. If I copy that, the graph is PDF which is a bell shape. mu = 0;
sd = 1;
ix = -3*sd:1e-3:3*sd; %covers more than 99% of the curve
iy = pdf('normal', ix, mu, sd);
plot(ix,iy);
However, with the data that I got from x=0.5+0.024*randn(251,1), my plot is not a bell shape. Am I missing something? thanks so much

Connectez-vous pour commenter.

Plus de réponses (2)

You have to distinguish between generating random numbers (data) from some distribution and the probability density function. There is nothing about the probability density function that is random. So which do you want?
x=0.5+0.024*randn(251,1);
hist(x)
Do you see the shape resembling a normal distribution from the above histogram?
Your original post said you wanted to generate data that follows a N(0.0.024^2) distribution that is exactly what the command I gave you does.
You can also generate the PDF for that distribution, but again, those are not the same things.

1 commentaire

hi Wayne, sorry about the confusion. In my initial post, I want to generate random values that follow normal distribution of mean=0 and sd=0.024. The code that you gave me do the job .
I would also like to know how to generate the PDF for the distribution, just to clariify myself a bit more. Thanks so much again

Connectez-vous pour commenter.

If you have the Statistics Toolbox, then
x = -0.1:1e-4:0.1;
y = normpdf(x,0,0.024);
plot(x,y)
If not
x = -0.1:1e-4:0.1;
sd = 0.024;
y = 1/sqrt(2*pi*sd^2).*exp(-x.^2/(2*sd^2));
plot(x,y)

1 commentaire

Hi Wayne, really appreciate your help. Thanks million. Now I understand a bit more.

Connectez-vous pour commenter.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by