% Approximation of a Gaussian Distribution

clear

% Number of samples
N = 1e6;

% Bin size
binSize = 0.1;

% Number of STD to include 
stdNum = 4;

% Generate random samples, and bin them
x = randn(N,1);
binVec = -stdNum:binSize:stdNum;
pdfApprox = hist(x,binVec);

% Generate the true Gaussian distribution
y = exp(-0.5*binVec.^2)/sqrt(2*pi);

bar(binVec,pdfApprox/(N*binSize));
title(['Gaussian Approximation.  Samples = ',num2str(N),', Bin Size = ',num2str(binSize)]);
hold on
plot(binVec,y,'r*');
hold off