How to add errorbars
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Ting-Yu Chueh
am 22 Sep. 2019
Kommentiert: Ting-Yu Chueh
am 22 Sep. 2019
Dear all,
I want to add the errorbar for each bar, but it didn't work out.
The code I wrote is below
Can anyone fix it ? Thanks!
figure;
TGmatch=7.15;
AGmatch=8.32;
TGnonmatch=7.56;
AGnonmatch=7.84;
adRT=[TGnonmatch AGnonmatch;TGmatch AGmatch];
h=bar(adRT);
set(get(gca, 'YLabel'),'String','accuracy-adjusted RT (ms/%)','FontSize',14);
set(gca, 'FontSize',14,'XTick',[1 2],'XTickLabel',{'Nonmatch','Match' })
set(get(gca, 'Title'),'String','(C) visual-spatial attention','FontSize',16);
ylim([0 10]);
set(gca,'YTick',1:2:10);
TGmatchSE=.25;
AGmatchSE=.44;
TGnonmatchSE=.29;
AGnonmatchSE=.41;
errorbar(1,TGmatch,TGmatchSE,'k');
errorbar(1,AGmatch,AGmatchSE,'k');
errorbar(2,TGnonmatch,TGnonmatchSE,'k');
errorbar(2,AGnonmatch,AGnonmatchSE,'k');
set(gca, 'Box', 'off');
set(gca,'color','none');
legend('TG','AG','Fontsize',14);
0 Kommentare
Akzeptierte Antwort
dpb
am 22 Sep. 2019
Bearbeitet: dpb
am 22 Sep. 2019
You forgot to add hold on before calling errorbar so that wiped out the barplot and then each subsequent call to it also will have overwritten the previous. But, that alone won't solve your problem because with a grouped bar, the locations aren't in the center of the bars but at the center of each group. I've complained for 20+ years and TMW has yet to do anything really positive to solve the horrendous interface to bar and to provide easy ways to do the obviously-needed such as this; I would strongly suggest to add your voice to the complaints about quality of implementation being lacking and the need for the facility to be included as a standard set of options in one manner or another. OK, editorializing over, see
<Answers:379570-how-can-i-place-my-error-bar-in-separate-bar-center> for example of how to locate the positions and to do what you're asking for.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Errorbars finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!