MATLAB: How to add the values to the top of the bars

plotplotting

Hi everbody
To add the values of bars (like as the image), what kind of a code can be written?
Thanks…
graf=[10 15]
bar(graf,0.2,'m')
set(gca,'XTickLabel',{'X','Y'})
ylabel( '% ')
grid on

Best Answer

Try this:
graf=[10 15]
bar(graf,0.2,'m')
set(gca,'XTickLabel',{'X','Y'})
ylabel( '% ')
xt = get(gca, 'XTick'); % Values For ‘X-Ticks’
text(xt, graf, {'10%','15%'}, 'VerticalAlignment','bottom', 'HorizontalAlignment','center')
set(gca, 'YLim',[0 20])
grid on
Related Question