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 Center および File ExchangeErrorbars についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by