How to add errorbars

조회 수: 1 (최근 30일)
Ting-Yu Chueh
Ting-Yu Chueh 2019년 9월 22일
댓글: 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.
  댓글 수: 1
Ting-Yu Chueh
Ting-Yu Chueh 2019년 9월 22일
OK. Thanks~

댓글을 달려면 로그인하십시오.

추가 답변 (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