Trouble adding error bars to bar graph

3 views (last 30 days)
I am trying to add error bars to bar graph. The figure looks fine if I run it without the error bars as just bar(coh). (see attached) I want to the bars to be groups as shown. I'm wondering if that grouping is messing up the error bars.
Thank you in advance for any help!
Hope you are all staying safe and healthy Matlab community.
x = 1:12;
coh = [0.9862, 0.9773
0.971, 0.9544
0.8969, 0.6791
0.8835, 0.9051
0.8558, 0.6727
0.6727, 0.8641];
errhigh = [0.0083, 0.0137
0.0137, 0.0274
0.0611, 0.1797
0.0688, 0.0563
0.1426, 0.1829
0.0875, 0.0799];
errlow = [0.0208, 0.034
0.043, 0.0661
0.1382, 0.3105
0.1533, 0.1288
0.1827, 0.3135
0.1879, 0.1743];
figure
bar(x,coh)
%bar(coh)
hold on
er = errorbar(x,coh,errlow,errhigh);
er.Color = [0 0 0];
er.LineStyle = 'none';
hold off
  3 Comments
dpb
dpb on 17 Mar 2020
In 40 years, TMW has yet to provide any decent hatching... :(
There are some submissions on File Exchange; all that I've used have warts of various severity; and whether any will work with bar I've never tried/looked.
Heidi Hirsh
Heidi Hirsh on 17 Mar 2020
Dang! I might hold off on that detail for now. The error bar issue is more critical at the moment. Thank you for the heads up!

Sign in to comment.

Accepted Answer

dpb
dpb on 17 Mar 2020
  9 Comments
dpb
dpb on 24 Mar 2020
Rearrange your groups/x values to match the groups you want highlighted the same.
Heidi Hirsh
Heidi Hirsh on 24 Mar 2020
I'm not sure I understand what you mean

Sign in to comment.

More Answers (0)

Categories

Find more on Discrete Data Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!