# interp1

One dimensional interpolation.

## Syntax

yi = interp1(x,y,xi)

yi = interp1(x,y,xi,method)

yi = interp1(x,y,xi,extrap)

yi = interp1(x,y,xi,method,extrap)

## Inputs

`x,y`- The known points with which to interpolate.
`xi`- The domain points at which to interpolate.
`method`- The available options are:
- 'linear'
- Returns the linear interpolation from the nearest neighbors.
- 'pchip'
- Returns shape preserving piece-wise cubic Hermite interpolation.
- 'spline'
- Returns the cubic spline interpolation.

`extrap`- The available options are:
- 'extrap'
- Allows extrapolation beyond the interval.
- 'noextrap'
- Does not allow extrapolation (default).

## Outputs

- yi
- The interpolated y values corresponding to
`xi`.

## Examples

With 'linear' method and no extrapolation:

```
x = [1,2,3,4,5];
y = [1,4,9,16,25];
xi = [1.5,2.5,3.5,4.5];
yi = interp1(x,y,xi,'linear')
```

```
yi = [Matrix] 1 x 4
2.50000 6.50000 12.50000 20.50000
```

With 'linear' method and extrapolation:

```
x = [1,2,3,4,5];
y = [1,4,9,16,25];
xi = [0.5,1.5,2.5,3.5,4.5,5.5];
yi = interp1(x,y,xi,'linear','extrap')
```

```
yi = [Matrix] 1 x 6
-0.50000 2.50000 6.50000 12.50000 20.50000 29.50000
```

With 'spline' method and no extrapolation:

```
x = [1,2,3,4,5];
y = [1,4,9,16,25];
xi = [1.5,2.5,3.5,4.5];
yi = interp1(x,y,xi,'spline')
```

```
yi = [Matrix] 1 x 4
2.25000 6.25000 12.25000 20.25000
```

## Comments

When `y` is a matrix, the function operates along the first dimension,
which is the column dimension in the 2D case. This convention is the opposite of
spline.

For the 'linear' method, duplicate `x` values are allowed
if the vector is sorted, indicating a discontinuous function. The function is treated as
right-continuous if `x` is in ascending order, and left-continuous if
descending. More than two identical `x` values are not allowed.

For methods other than 'linear', `x` values must be
unique.

The 'spline' method uses the not-a-knot cubic spline.