It is a known problem that the built-in "errorbar.m" sets the width of the error bars horizontal lines automatically (see http://www.mathworks.com/matlabcentral/answers/166285-control-errorbar-width-in-matlab-r2014b), meaning that different graphs or lines might have inconsistently formatted error bars. Up to R2014a, there was a hack to get around this, but it doesn't work post R2014b.
This program draws error bars as specified, simply using the "plot" function to draw lines of appropriate size. You can specify their width relative to the x-axis size ("units") or in absolute terms ("centi", "inches", etc.). You can use it much like errorbar, but with extra terms, e.g.
>> h=terrorbar([1 2 3],[2 4 6],[.5 .7 .9],[.5 .7 .9],0.25,'centi');
...and sensible variants of this also work (e.g. omitting the uppererrorbarheight gets you symmetric error bars).
NB This function doesn't draw a line through the points, nor bars for a bar chart. Use your usual other program to do that. Using "hold on" you can generally draw on the error bars before or after, depending on whether you want the error bars to be underneath the markers (normal for line graphs) or on to of them (normal for bar charts).
If needed you can tweak the error bar widths after, using this same function:
>> terrorbar(h,0.5) %assumes same units as before
>> terrorbar(0.5,'centi') %is applied to all error bars in the current figure.
If you resize the figure after, the errorbars will cunningly update their width appropriately (e.g. if you specified their width in centimetres, they will remain as wide). However, if you update the axis width, the error bars may not behave as you want. You can always reinforce the original size requests by running terrorbar, even without parameters:
* Not yet programmed for use with a logarithmic x-axis
* May get stuck in a recursive loop if the error bars are very wide compared to everything else. But then that's a rather unlikely scenario...
* Not yet thoroughly tested, except for what I wanted it to do -- let me know if you find another bug.
I also hope to have the logarithmic x-axis function soon.
Could you provide the code for a logarithmic x-axis? Thanks
gives me the flexibility I was looking for. thank you!
'DisplayName','mylegendtext', 'tag','data' is not necessary, because terrorbar creates only the errorbars, not the points.
terrorbar does not accept all parameters of the matlab errorbar() function. How can I convert the following function to terrorbar syntax?
errorbar(x, y, yErr, 'DisplayName','mylegendtext', 'tag','data');
Could you upload the source to a public githoster? Users could update and download and contribute easier then.
easy to use and clear
Nice workaround for adjustable length of errorbars. Hope to have the logarithmic x-axis function soon. Thanks.
minor editing of text formatting