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

版本 1.0.0.0 (10.4 KB) 作者: Trevor Agus
Draws error bars (as line objects), allowing you to specify the width of the horizontal bars
1.1K 次下载
更新时间 2015/8/2

查看许可证

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.

引用格式

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. 检索时间: .

MATLAB 版本兼容性
创建方式 R2014b
兼容任何版本
平台兼容性
Windows macOS Linux
类别
Help CenterMATLAB Answers 中查找有关 Errorbars 的更多信息
致谢

启发作品: superbar

Community Treasure Hunt

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

Start Hunting!
版本 已发布 发行说明
1.0.0.0

minor editing of text formatting