How to make error bars on double bar graph?

7 views (last 30 days)
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

Accepted Answer

Star Strider
Star Strider on 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.)
.

More Answers (0)

Categories

Find more on Line Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!