Code covered by the BSD License

5.0

5.0 | 11 ratings Rate this file 185 Downloads (last 30 days) File Size: 2.97 KB File ID: #26311

07 Jan 2010 (Updated 18 Jan 2010)

Creates an attractive shaded error region rather than discrete bars.

### Editor's Notes:

This file was selected as MATLAB Central Pick of the Week

File Information
Description

Creates a continuous shaded error region rather than discrete bars. Error region can either be specified explicitly or calculated on the fly based upon function handles. Handles of the plot objects are returned in a convenient structure.

Purpose
Makes a 2-d line plot with a pretty shaded error bar made
using patch. Error bar color is chosen automatically.

Inputs
x - vector of x values
y - vector of y values or a matrix of n observations by m cases
where m has length(x);
errBar - if a vector we draw symmetric errorbars. If it has a
size of [2,length(x)] then we draw asymmetric error bars
with row 1 being the upper bar and row 2 being the lower
bar. ** alternatively ** errBar can be a cellArray of
two function handles. The first defines which statistic
the line should be and the second defines the error
bar.
lineProps - [optional,'-k' by default] defines the properties of
the data line. e.g.:
'or-', or {'-or','markerfacecolor',[1,0.2,0.2]}
transparent - [optional, 0 by default] if ==1 the shaded error
bar is made transparent, which forces the renderer
to be openGl. This means that saved .eps files
won't look so good because they'll be rasters not
vectors.

Outputs
H - a structure of handles to the generated plot objects.

Examples
y=randn(30,80); x=1:size(y,2);

Overlay two transparent lines
y=randn(30,80)*10; x=(1:size(y,2))-40;
hold on
y=ones(30,1)*x; y=y+0.06*y.^2+randn(size(y))*10;

Rob Campbell - November 2009

Acknowledgements
MATLAB release MATLAB 7.8 (R2009a)
12 Dec 2013

Very powerful and convenient to use!

10 Nov 2013

Now thank you very much, your second option works perfect. This is what I need. I wish I can give you 5 stars now :).
You should include this in the description. It's really helpful :).
Thank you one more time

10 Nov 2013

Slavi, the behavior you see is is typical of functions such as this because each line is made up of multiple plot elements and the legend command doesn't know anything about that. There are two ways for you to proceed. Firstly, use the "axes" command in order to make a set of legend axes, then build your own legend within these axes. It'll be a bit of pain, but you get the most flexibility this way. Secondly, you can tell the legend command which plot elements to use:

hold on
>> A %This is what's in the handles

A =

mainLine: 174.0065
patch: 175.0050
edge: [176.0026 177.0026]

legend([A.mainLine,B.mainLine],'A','B')

10 Nov 2013

Very helpful :). But unfortunately I can't display only the Y-values in the legend. There are more additional data sets in the legend I can't delete.
Do you have any idea? :)

20 Feb 2013
08 Feb 2013

what is shade error bar? i try to execute it but cannot.

27 Jan 2013
07 Aug 2012
10 Jul 2012
29 May 2012
02 Mar 2012

12 Apr 2011
07 Mar 2010