I would post this in Computational Science Stack Exchange, but I think it is simply too easy to post there. People post easier questions than this here all the time. I want to superimpose the pdf of a normal distribution on a histogram to show that the numbers generating the histogram appear to be drawn from a near-normal distribution. I am using Matlab, and I'm using Matlab "hist" command with no options (at the moment). When I plot the histogram and the normal curve, they don't match. I want to scale the histogram (not the pdf) so that they agree. I'm not sure how to do it. I know I have to use the number of "samples" in the histogram but I'm not sure if I need to use the bin width, or even how to find what bin width Matlab is using. There is a way to draw histograms in Matlab where you tell Matlab what the bins are, and I can do that if I need to.
I got "histfit" to work. This plots the histogram together with the scaled normal curve that best fits the data. This is almost but not exactly what I want. I want to specify the parameters of the normal curve myself directly.
Below is the Matlab code. In the resulting histogram, the bars are way taller than the pdf, and the total area of the bars is much bigger than 1.
I would like a simple solution, one that does not involve GUI's, toolboxes, etc.
N=2; numsamples=100; mat=rand(N, numsamples); avg=sum(mat)/N; %produces row vector from averages of columns hist(avg) %draws histogram %Below is an attempt to graph the pdf of the normal distribution on top of %the histogram. If they are properly scaled, they should match up. I %don't know how to properly scale it. hold on x=-1:0.001:1; y=normpdf(x,0.5,sqrt(1/12)); %numbers in vector avg should be roughly normally distributed %w/ mean 0.5 and std.dev'n sqrt(1/12) %Below is an attempt to graph the pdf of the normal distribution on top of %the histogram. If they are properly scaled, they should match up. I %don't know how to properly scale it hold on x=0:0.01:1; %row vector of values from 0 to 1 in increments of 0.01 y=normpdf(x,0.5,sqrt(1/12));%row vector of pdf of normal random variable %w/ mean 0.5 and %std. dev'n 1/sqrt(12) %evaluated at the numbers in x plot(x,y)