MATLAB: Bar Plots with errorbars with limits

bar ploterrorbarerrorbar limitMATLAB

I am tring to draw a bar plot where my highest value on y-axis is 1. Then I want to draw errorbars(standard error of the mean) for each bar. But while doing so, for my highest bar, the errorbar is crossing my highest limit 1. How can I limit my errorbars for my plot. Thank you.

Best Answer

Do you mean something like this?
% Pretend data
x = linspace(0,10,25);
y = linspace(0,1,25);
se = y/10;
% Amount that error bar will extend above 1
se_extra = (y + se) - 1;
% Amount of error bar to chop off upper bar
se_chop = max(0,se_extra);
% Amount to plot
se_top = se - se_chop;
se_bot = se;
figure
errorbar(x,y,se_bot,se_top)
xlim([0 11])
ylim([0 1])
Screen Shot 2020-02-10 at 2.29.00 PM.png
Related Question