function [h  ,hn, xspan]=histn(data, startx, binsize, endx)
%   [h,hn, xspan]=histn(data, startx, binsize, endx)
%  data -- data to be shown
%  startx, endx is domain for the data, usually min(data),max(data)
%  binsize is the bin size of the histogram
% EXAMPLE
% >> data = betarnd(2, 4, [1, 10000]);
% >> histn(data, 0,0.05,1);
% >> hold on
% >> plot( 0:0.005:1, betapdf(0:0.005:1, 2,4), 'r','linewidth',3)
%
xspan=[startx:binsize:endx];
h=hist(data,xspan); % Generate histogram
hn=h/(length(data)*binsize); % Normalize histogram to have area 1
bar(xspan,hn); % Plot histogram