Asked by Sandor Toth
on 11 Dec 2014

Pre R2014b Matlab versions allowed the separate control of the length of the top and bottom error bar lines separately through the 'xdata' property. This is not possible any more in Matlab R2014b, where the 'xdata' property contains only the x coordinates of the data points but not the error bar lines. Is there a way to control the error bar line length in Matlab R2014b?

Answer by Sean de Wolski
on 7 Jan 2015

Pre-R2014b, this was possible because the errorbar series had children which were lines you could adjust. Since that's no longer the case, this approach no longer works.

I'd at least recommend contacting tech-support with your use-case and reasoning so that they can add an enhancement request for it.

pedro
on 26 Jan 2017

Scott Webster
on 7 Mar 2017

Scott Webster
on 14 Mar 2017

I received a response from MathWorks. A CapSize property has been added to the errorbars as of R2016b. Here is my previous example updated to use this functionality (with excessive crossbar width):

x=[5 25];

y=[10 10];

err=[5 5];

hold on

h=errorbar(x,y,err,'ro');

h.CapSize = 12;

x=[13 17];

h=errorbar(x,y,err,'bo');

h.CapSize = 12;

print('-dpng','errorbars3.png');

The resultant plot is as follows.

However, I also noticed that the errorbar width was actually ok for this example in R2016b before I even adjusted the capsize, so it seems that some other general improvements were made as well.

Finally, MathWorks also provided the following code example for manually drawing the crossbars in case you don't have R2016b.

% Create errorbar

X = 0:pi/10:pi;

Y = sin(X) + 1;

E = std(Y) * ones(size(X));

ha = errorbar(X, Y, E);

% Width of the top and bottom lines of errorbar

xlength = 0.1;

% Make horizontal lines with 'line'

for k = 1:length(X)

x = [X(k) - xlength, X(k) + xlength];

y_h = [Y(k) + E(k), Y(k) + E(k)];

line(x, y_h);

y_b = [Y(k) - E(k), Y(k) - E(k)];

line(x, y_b);

end

Sign in to comment.

Answer by Sören Fechner
on 30 Jan 2015

I have the same Problem. Have you found a solution yet ?

Answer by Ramaprasad Kulkarni
on 20 Dec 2016

You guys might have found a solution, but just putting this out there:

An alternate and easier option to control the width of the top/bottom crossbars is to plot each pair of [x(i), y(i)] points and corresponding errorbar(x(i),y(i),err(i)). This ensures the width of the top/bottom crossbars is 0.02*x(i).

The downside of this approach is you have to use an unnecessary for loop to go over all the values in the X/Y vectors.

Scott Webster
on 3 Mar 2017

Sign in to comment.

Opportunities for recent engineering grads.

Apply Today
## 8 Comments

## Scott Webster (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/166285-control-errorbar-width-in-matlab-r2014b#comment_256906

## Oleg Komarov (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/166285-control-errorbar-width-in-matlab-r2014b#comment_258729

## Scott Webster (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/166285-control-errorbar-width-in-matlab-r2014b#comment_259149

## Oleg Komarov (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/166285-control-errorbar-width-in-matlab-r2014b#comment_259386

## Scott Webster (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/166285-control-errorbar-width-in-matlab-r2014b#comment_259448

## Axel (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/166285-control-errorbar-width-in-matlab-r2014b#comment_260562

## Trevor Agus (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/166285-control-errorbar-width-in-matlab-r2014b#comment_301642

## Brandon Madsen (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/166285-control-errorbar-width-in-matlab-r2014b#comment_528577

Sign in to comment.