Replace last two lines by
bar(Y,'hist'); %// this uses 1:numel(Y) as x axis values
set(gca,'XTick',.5:numel(Y)+.5,'Xticklabel',BinEdges,'XLim',[.5 numel(Y)+.5])
This plots the bars at equal-spaced x positions (1, 2, 3, ...). It then adds the labels of your bin edges (which do not correspond to the actual x values, but no matter) and sets the x axis limits according to the values actually used for the x axis.