# errorbar

Plot error bars along curve

## Syntax

`errorbar(Y,E)errorbar(X,Y,E)errorbar(X,Y,L,U)errorbar(...,LineSpec)errorbar(ax,...)h = errorbar(...)`

## Description

Error bars show the confidence intervals of data or the deviation along a curve.

`errorbar(Y,E)` plots `Y` and draws an error bar at each element of `Y`. The error bar is a distance of `E(i)` above and below the curve so that each bar is symmetric and `2*E(i)` long.

`errorbar(X,Y,E)` plots `Y` versus `X` with symmetric error bars `2*E(i)` long. `X`, `Y`, `E` must be the same size. When they are vectors, each error bar is a distance of `E(i)` above and below the point defined by `(X(i),Y(i))`. When they are matrices, each error bar is a distance of `E(i,j)` above and below the point defined by `(X(i,j),Y(i,j))`.

`errorbar(X,Y,L,U)` plots `X` versus `Y` with error bars `L(i)+U(i)` long specifying the lower and upper error bars. `X`, `Y`, `L`, and `U` must be the same size. When they are vectors, each error bar is a distance of `L(i)` below and `U(i)` above the point defined by `(X(i),Y(i))`. When they are matrices, each error bar is a distance of `L(i,j)` below and `U(i,j)` above the point defined by `(X(i,j),Y(i,j))`.

`errorbar(...,LineSpec)` uses the color and line style specified by the string `'LineSpec'`. The color is applied to the data line and error bars. The linestyle and marker are applied to the data line only. See `linespec` for examples of styles.

`errorbar(ax,...)` plots into the axes specified by `ax` instead of the current axes.

`h = errorbar(...)` returns handles to the errorbarseries objects created. `errorbar` creates one object for vector input arguments and one object per column for matrix input arguments. See Errorbar Series Properties for more information.

When the arguments are all matrices, `errorbar` draws one line per matrix column. If `X` and `Y` are vectors, they specify one curve.

## Examples

collapse all

### Symmetric Error Bars

Draw symmetric error bars that are two standard deviation units in length.

```x = 0:pi/10:pi; y = sin(x); e = std(y)*ones(size(x)); figure errorbar(x,y,e) ```

### Change Error Bar Marker and Color

Load the `count` data set to get the three-column matrix `count` that contains traffic volume for three street locations over the course of a day. Compute the mean of `count` for each row.

```load count.dat; y = mean(count,2); ```

Compute the standard deviation of `count` for each row and normalize by the number of elements in the sample by setting the second input argument to 1.

```e = std(count,1,2); ```

Plot the computed average traffic volume, `y`, and the computed standard deviations, `e`, for the three street locations. Set the `LineSpec` to specify a red color, cross markers, and no line.

```figure errorbar(y,e,'rx') ```