MATLAB: Error bars in bar plot with categories

bar plotcategories;errorbars

Hello
I have a bar plot with 3 categories where I want to insert error bars.
I've been trying it for a long time, but I can't find the solution.
x are the categories
y the values
errorplus and errorminus the errors values.
Can someone hel me?
Thank you very much!
x=categorical({'Hip';'Knee';'Ankle'});
y=[21.0416,19.5461,50;30.003601074218750,24.056737899780273,50;22.604316711425780,26.007211685180664,35];
errorplus=[0.434635639190674,1.783290743827820,0;1.722714424133301,1.000267505645752,0;0.471254885196686,2.722285032272339,0];
errorminus=errorplus;
figure;
bar(x,y);
title('Range of Motion','FontSize',18)
ylabel('Angle Values [°]','FontSize',18)
set(gca,'linewidth',2,'FontSize',14)
ylim([0 60]);

Best Answer

This seems to be an XOR situation. Apparently, it is possible to have categorical x-values or errorbar bars but not both.
This requires non-categorical x-values, although it produces the appropriate final result:
x=categorical({'Hip';'Knee';'Ankle'});
y=[21.0416,19.5461,50;30.003601074218750,24.056737899780273,50;22.604316711425780,26.007211685180664,35];
errorplus=[0.434635639190674,1.783290743827820,0;1.722714424133301,1.000267505645752,0;0.471254885196686,2.722285032272339,0];
errorminus=errorplus;
figure;
bar(x,y);
hBar = bar(y, 0.8); % Return ‘bar’ Handle
for k1 = 1:size(y,2)
ctr(k1,:) = bsxfun(@plus, hBar(k1).XData, hBar(k1).XOffset'); % Note: ‘XOffset’ Is An Undocumented Feature, This Selects The ‘bar’ Centres
ydt(k1,:) = hBar(k1).YData; % Individual Bar Heights
end
hold on
errorbar(ctr, ydt, errorplus, '.r') % Plot Error Bars
hold off
title('Range of Motion','FontSize',18)
ylabel('Angle Values [°]','FontSize',18)
set(gca,'linewidth',2,'FontSize',14)
ylim([0 60]);
set(gca,'XTickLabel',x)
producing this plot:
1error bars in bar plot with categories - 2019 12 12.png