From: Wendy on
Hi all,

I have a grouped bar group, for example,

data = rand(3,4).*10;
bar(data)

I want to annotate the first bar in each group, then the second, and so on. I am wondering if there is a way that I can get the x location of each bar.

Thank you in advance,
Wendy
From: us on
"Wendy " <wlq121(a)gmail.com> wrote in message <i0qtiu$dvk$1(a)fred.mathworks.com>...
> Hi all,
>
> I have a grouped bar group, for example,
>
> data = rand(3,4).*10;
> bar(data)
>
> I want to annotate the first bar in each group, then the second, and so on. I am wondering if there is a way that I can get the x location of each bar.
>
> Thank you in advance,
> Wendy

one of the solutions

m=rand(3,4).*10;
bh=bar(m);
bc=get(bh,'children');
bp=get([bc{:}],'xdata');
bp=cat(2,bp{:}); % <- X coordinates of each bar-patch...
bd=diff(bp([1,4],1)); % <- length of each bar-patch

us