How to add errorbars

7 次查看(过去 30 天)
Ting-Yu Chueh
Ting-Yu Chueh 2019-9-22
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);

采纳的回答

dpb
dpb 2019-9-22
编辑:dpb 2019-9-22
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Errorbars 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by