MATLAB Answers

Plotting normal distribution with negative x range

3 views (last 30 days)
Yonni f
Yonni f on 13 Mar 2016
Commented: Yonni f on 13 Mar 2016
When plotting a normal distribution using the pdf command, setting the x-value range to negative values seems to give me a wrong answer. Quite likely this is me misunderstanding the command but any help would be appreciated.
I obtain the parameters using the code:
fit_parameters = fitdist(double(data_to_fit(:)),'Normal');
I then try plot it as follows:
plot(pdf(fit_parameters,x_values)
Considering that the mean is just below 0, I've set my x-values to something like -80:80. What I get, however, is a curve centred at 80 which is obviously wrong.
I am using MatLab 2013
Thanks, Y

Accepted Answer

John D'Errico
John D'Errico on 13 Mar 2016
Edited: John D'Errico on 13 Mar 2016
When you call plot with ONE argument, it assumes that the x-axis is the integers, 1:numel(y). So, your expected x-axis would be 1:161. From what you have said, the mean will fall right around 80 as you plotted it.
Instead, try this:
plot(x_values,pdf(fit_parameters,x_values))
  1 Comment
Yonni f
Yonni f on 13 Mar 2016
Jeez, thanks so much. There's nothing quite like banging your head against the wall for hours when the answer so simple!

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!