How to make error bars on double bar graph?

조회 수: 14 (최근 30일)
Chelsie Boodoo
Chelsie Boodoo 2022년 7월 30일
댓글: Star Strider 2022년 7월 31일
Hi i am trying to get error bars on my double bar graphs but it wont show. I am using MATLAB R2020a. Please help!
y=[6 8;8 10; 9 99;19 68;20 52;];
x = [categorical({'Control' , 'Target', 'NT1', 'NT2', 'NT3'})];
bar(x,y)
figure;
hold on
b= bar(x, y);
ax = gca;
ax.FontSize = 14;
xlabel("Sample", 'FontSize', 20);
ylabel("Peaks", 'FontSize', 20);
title("Specificity", 'FontSize', 26);
error_data=[];
error_data= [1 2; 1 3; 8 3; 4 2; 2 2;];
errorbar(x, y, error_data,'k','linestyle','none');
errorbar(x, y, error_data,'k','linestyle','none');
hold off

채택된 답변

Star Strider
Star Strider 2022년 7월 31일
I have no idea when XEndPoints and YEndPoints was introduced, however it was relatively recently (within the last few years).
This works in R2022a
y=[6 8;8 10; 9 99;19 68;20 52;];
error_data= [1 2; 1 3; 8 3; 4 2; 2 2;];
x = [categorical({'Control' , 'Target', 'NT1', 'NT2', 'NT3'})];
figure
hold on
hb = bar(x, y);
for k = 1:numel(hb)
errorbar(hb(k).XEndPoints, hb(k).YEndPoints, error_data(:,k), '.k', 'MarkerSize',0.1)
end
ax = gca;
ax.FontSize = 14;
xlabel("Sample", 'FontSize', 20);
ylabel("Peaks", 'FontSize', 20);
title("Specificity", 'FontSize', 26);
If this doesn’t work in your version, go here for an alternative approach that probably will. (It fails in R2022a since XOffset may no longer exist, so I cannot illustrate it here.)
.
  댓글 수: 2
Chelsie Boodoo
Chelsie Boodoo 2022년 7월 31일
Thanks it worked!!!!
Star Strider
Star Strider 2022년 7월 31일
As always, my pleasure!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by