% Matlab can do histograms better than a spreadsheet.

% put your data in here as an array
% data samplesize = 10
% data = [1,2,3,2,1,5,-2,-1,0,-3];
% or read it in from a file
% or here, a random number generator created synthetic data
% could also make yout and xout arrays by hand from your notebook
datasamplesize = 1000;
randommean = 1.1;
randomsigma = 1.3;
data = randomsigma*randn(datasamplesize,1) + randommean;

% set up bins and max and min for your histogram
% you know the data, so choose a range appropriate.
histbinsize = 1.0
histx = [-4:histbinsize:4];

% Now actually generate a histogram from those data
% For matlab R2014a and earlier, use hist()
% For matlab R2014b and later, this might work, or use histogram()
[yout,xout] = hist(data,histx);
% could also make yout and xout arrays by hand from your notebook
% and skip the above steps

% Use matlab to compute the standard deviation and mean from data
mysigma = std(data)
mymean = mean(data)

% create a Gaussian function (also called the Normal function)
% with the data mean and sigma !
% keep in mind, the Gaussian is a continuous PDF (not discrete)
% so we can put a non-integer step size in here.
% There is probably a poisspdf by the way, or code one yourself.
normx = [-4:.1:4];
norm = normpdf(normx,mymean,mysigma)

% norm is a pdf that integrates to one.
% your data integrates to datasample size, and is binned.
% to plot them on top of each other, scale the Gaussian
normscale = datasamplesize*histbinsize


% now plot what you got
mybarplot = bar(xout,yout);

% make the plot less sucky
set(gcf,'color','white')
set(gca, 'Box', 'off', 'LineWidth',2, 'FontSize', 16)

hold on

mygaussplot = plot(normx,norm*datasamplesize*histbinsize);
set(mygaussplot, 'LineWidth',3,'Color',[0. 0. 0.])

hold off

% continue to make the plot readable and communicate something
myXLabel = xlabel('number of counts','FontSize',16);
myYLabel = ylabel('occurances in the data set','FontSize',16);
myTitle = title('illustration of a Gaussian on data','FontSize',16);
