terrorbar.m: Error bars with controlled widths post-R2014b

Draws error bars (as line objects), allowing you to specify the width of the horizontal bars
1,1K descargas
Actualizado 2 ago 2015

Ver licencia

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');
i.e.
>> h=terrorbar(xvalues,yvalues,lowererrorrbarheight,uppererrorbarheight,errorbarwidth,widthunits);
...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,'centi')
or
>> terrorbar(h,0.5) %assumes same units as before
or
>> 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:
>> terrorbar

Known problems:

* 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.

Citar como

Trevor Agus (2024). terrorbar.m: Error bars with controlled widths post-R2014b (https://www.mathworks.com/matlabcentral/fileexchange/52367-terrorbar-m-error-bars-with-controlled-widths-post-r2014b), MATLAB Central File Exchange. Recuperado .

Compatibilidad con la versión de MATLAB
Se creó con R2014b
Compatible con cualquier versión
Compatibilidad con las plataformas
Windows macOS Linux
Categorías
Más información sobre Errorbars en Help Center y MATLAB Answers.
Agradecimientos

Inspiración para: superbar

Community Treasure Hunt

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

Start Hunting!
Versión Publicado Notas de la versión
1.0.0.0

minor editing of text formatting