How to make error bars on double bar graph?

14 Ansichten (letzte 30 Tage)
Chelsie Boodoo
Chelsie Boodoo am 30 Jul. 2022
Kommentiert: Star Strider am 31 Jul. 2022
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

Akzeptierte Antwort

Star Strider
Star Strider am 31 Jul. 2022
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 Kommentare
Chelsie Boodoo
Chelsie Boodoo am 31 Jul. 2022
Thanks it worked!!!!
Star Strider
Star Strider am 31 Jul. 2022
As always, my pleasure!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu 2-D and 3-D Plots 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!

Translated by