the following is my code. I want to put values on top of the bars but I could not solve the problem. I have gone through the previous but could not figure out the exact positioning.
x = [20 40 60 80 100];
y = [0.0036 0.0149;0.0033 0.0149;0.0023 0.0192;0.0021 0.0235;0.0018 0.0279];
bar(x,y)
a = (1:size(y,1)).';
x_check = [a-0.25 a+0.25];
for k=1:size(y,1)
for m = 1:size(y,2)
text(x_check(k,m),y(k,m),num2str(y(k,m),'%0.2f'),...
'HorizontalAlignment','center',...
'VerticalAlignment','bottom')
end
end

 Accepted Answer

x = [20 40 60 80 100]';
y = [0.0036 0.0149;0.0033 0.0149;0.0023 0.0192;0.0021 0.0235;0.0018 0.0279];
bar(x,y)
text(x, y(:,1), num2str(y(:,1)), 'HorizontalAlignment','center', 'VerticalAlignment','bottom')
text(x, y(:,2), num2str(y(:,1)), 'HorizontalAlignment','center', 'VerticalAlignment','bottom')

3 Comments

Thank you very much. It almost works but the alignment does not work. Can you have a look.
Check the properties of text, you can try chaning the allignment which suits you.
I will try. Thank you very much.

Sign in to comment.

More Answers (0)

Categories

Find more on Graphics Objects in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!