
% Longin Jan Latecki, latecki@temple.edu, Sep. 2009
% plots histogram of samples drawn from a Gaussian with mean zero and std one
% and plots the Gaussian with mean zero and std one
% the values of histogram are normalized so that the sum of the area of the
% histgoram bars (rectangles) is equal to one
% This way both plots are directly comparable, since the area under the
% Gaussian curve is also one.

x = -5:0.1:5;
g=normpdf(x,0,1);

samples=randn(1000,1);
%samples = normrnd(0,1,1000,1);
[hs, hx] = hist(samples,x);
hs=(hs/1000)*(101/10);
figure; bar(x,hs,'r'); %plots normalized histogram
hold on
plot(x,g,'LineWidth',3); %plots the Gaussian with mean zero and std one
title('Gaussian N(0,1) and the histogram of samples from N(0,1)')

