how to use code for printing values on top of vertical bars with horizontal bars?

3 次查看(过去 30 天)
Hello,
I want to try horizontal bars and print the values right of the bars.
My actual code which prints the values on top of each bar is the following ....
% Find the x location of each bar
xvals = unique(cell2mat(get(findall(hb,'type','patch'),'xdata')));
xvals = mean(reshape(xvals,2,[]));
% Put the text there
text(xvals,[DataFps1 DataFps2 DataFps3 DataFps4 DataFps5], ...
{[DataFpsLabels1 DataFpsLabels2 DataFpsLabels3 DataFpsLabels4 DataFpsLabels5]},...
'Vert','bot','horiz','cen','FontName','Arial','Fontsize',8);
My problem is that unfortunately I don't understand this code, which means I cannot alter it correctly. I have this code from another question which I asked on this forum. When I use "hbar"for horizontal bars, the values which you can see on top of the bars disapper.
How the code has to be altered?
Thanks, David

回答(1 个)

Image Analyst
Image Analyst 2013-2-4
They're the x and y values. In text, try adding an offset to the x values and reducing the y values by some factor, say half:
xvals+10,[DataFps1 DataFps2 DataFps3 DataFps4 DataFps5]* 0.5
  1 个评论
David
David 2013-2-4
I tried but it won't work. It gives me an error:
Error using text
X and Y must be the same length
it seems when using barh instead of bar the xvals variable only contains 13 elements and not 25 as before.
It seems that something in these two lines is not working:
xvals = unique(cell2mat(get(findall(hb,'type','patch'),'xdata')));
xvals = mean(reshape(xvals,2,[]));

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by