Time (min) |
0 | 6 | 10 | 13 | 17 | 20 | 28 | 32 |

Velocity(km/hr) |
0 | 6.67 | 17.33 | 42.67 | 37.33 | 30.10 | 29.31 | 28.74 |

## Linear Interpolation:

Linear interpolation is so named because it is equivalent to connecting the data points with a straight line.

Linear interpolation in MATLAB is obtained with the *interp1* and *interp2* functions.*interp1* is used to linearly interpolate a function of one variable only: y =f(x)

Where as *interp2* is used to linearly interpolate a function of two variables: z = f(x,y)

The syntax of *interp1* is rather simple.

*interp1(x,y,est_x)*

where,

x is a vector containing independent variable data;

y is a vector containing dependent variable data;

est_x is vector containing the value(s) of independent variable at which we want to interpolates.

Lets see how does m-file looks like:

m-file will be something like this

*clc
clear
x = [0 6 10 13 17 20 28 32];
y = [0 6.67 17.33 42.67 37.33 30.10 29.31 28.74];
x_est = [15 23];
y_est = interp1(x,y,x_est) *

## Cubic-Spline Interpolation:

In Spline interpolation we get smooth curve of the function through a set of points rather than sharp edges at data points.

The syntax of Spline interpolation in MATLAB is very similar to linear interpolation. We just have to replace *‘interp1’* with *‘spline’*

Therefore,

*spline(x,y,est_x)*

where,

x is a vector containing independent variable data;

y is a vector containing dependent variable data;

est_x is vector containing the value(s) of independent variable at which we want to interpolates.

*clc
clear
x = [0 6 10 13 17 20 28 32];
y = [0 6.67 17.33 42.67 37.33 30.10 29.31 28.74];
x_est = [15 23];
y_est = spline(x,y,x_est)*

For more stuff on Numerical Analysis using MATLAB,

Follow @Hammad_Ansari
#1 by

Jimon October 20, 2011 - 12:25 amHi, I enjoyed your post on interpolation of Time and Velocity! Great stuff. I am interested in using Matlab to perform a cubic interpolation of animal tracks so that I can create a smooth track/line for animal movements/locations. I have a large number of lat/long locations for an animal that I tracked, with each location having a known time (e.g. 05:15), and I would like to interpolate new lat/long locations at a specific time interval (e.g. every hour). I’m not sure how to accomplish this and was hoping that you may have some advice.

Thanks.

#2 by

Jimon October 20, 2011 - 12:26 am–