Functions > Data Analysis > Interpolation and Prediction > Example: Linear Interpolation
Example: Linear Interpolation
Use the linterp function to perform linear interpolation.
1. Define a set of y values.
2. Define a matching set of x values. These values need to be in increasing order.
3. Define a vector of x values for which you want to interpolate the curve.
4. Call the linterp function to perform linear interpolation between the data points.
5. Plot the data points and the interpolated curve.
As expected, the linterp function draws a straight line between each set of data points.
The interpolation assumes that the last approximation function, the one calculated between the last two points, continues to be true for all other points on that end of the range. This assumption is seldom appropriate. Different methods exist to predict values outside of a data range.
A curve created using linear interpolation is not smooth at each connecting data point, so there are no defined derivatives of the interpolated curve. For this reason, you may wish to use a cubic spline or a B-spline to fit your data.