Histogram plot and Gaussian
10 views (last 30 days)
Show older comments
Hi, I know this question has been quite popular and asked before, but based on the answers that I found online I am still not able to fix my problem. I have two populations (vectors) of N elements each, and they are both normally distributed (actually, generated with a Monte Carlo method which gives an almost-normal distribution, as it should). So far no problem.
Now, I would like to plot not only these two distributions as histograms, but also overimpose to them their related Gaussian distribution (not normalized with respect to the total number of elements N but keeping the "ratio" of the original histogram, that is keeping the graph with the frequencies).
My code is something like this:
% After generating R1 and R2 vectors...
% First, plot the histograms (with 50 "containers" each)
hist(R1,50);
hist(R2,50);
% Then, I retrieve the normal pdf and multiply each element of it
% in order to "denormalize". Multiply by N times the number of
% containers of the histogram
X = linspace(0,10000,7000);
Y1 = normpdf(X,mean(R1),std(R1)).*(N*50);
Y2 = normpdf(X,mean(R2),std(R2)).*(N*50);
plot(X,Y1,'r');
plot(X,Y2,'r');
hold off;
But unfortunately, the output looks like this (the Red lines, identifying the associated Gaussian curve, do not seem to fit properly the histogram distribution plot...):
What could my problem be?
Thanks a lot in advance for your valuable help!
Paolo
0 Comments
Answers (0)
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!