Error bars for every other bar

2 visualizzazioni (ultimi 30 giorni)
Andre White
Andre White il 14 Dic 2022
Commentato: Andre White il 14 Dic 2022
Hi everyone:
I am trying to set an error bar on every other bar. The error bar goes where each tick label is located. I am using the following code:
figure
x=1:4;
o_tip=[10.6,0.5300,1.3158,5.3300];
lower=[0.1900, 0.0500,0.0478, 1.3500];
upper=[ 0.1200, 0.0600, 0.0942, 1.4400];
kap=[10.0000,0.5000,3.4000,4.4000];
b=bar(x,[o_tip;kap]);
hold on
er=errorbar(x,o_tip,lower,upper);
%er.Color = [0 0 0];
er.LineStyle = 'none';
Can you please help me to solve this problem?
Thank you

Risposta accettata

Dave B
Dave B il 14 Dic 2022
I think what you're trying to do is put the errorbars on the first bar series? You can do this using the XEndPoints from the bar, which include not only the x values but the offset that's used by bar to make the grouped bar chart:
x=1:4;
o_tip=[10.6,0.5300,1.3158,5.3300];
lower=[0.1900, 0.0500,0.0478, 1.3500];
upper=[ 0.1200, 0.0600, 0.0942, 1.4400];
kap=[10.0000,0.5000,3.4000,4.4000];
b=bar(x,[o_tip;kap]);
hold on
er=errorbar(b(1).XEndPoints,o_tip,lower,upper);
er.Color = [0 0 0];
er.LineStyle = 'none';
(If you then want to put errorbars on the second series, just use b(2) in place of b(1), to get the middle of the orange bars)

Più risposte (0)

Categorie

Scopri di più su Errorbars in Help Center e File Exchange

Tag

Prodotti


Release

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by