interp2

Two dimensional interpolation.

Syntax

zi = interp2(x,y,z,xi,yi)

zi = interp2(x,y,z,xi,yi,method)

zi = interp2(x,y,z,xi,yi,method,extrap)

Inputs

x,y,z
The point coordinate values with which to interpolate.
See Comments for the dimension options.
Type: double
Dimension: vector | matrix
z
The grid of function values with which to interpolate.
Type: double
Dimension: matrix
xi,yi
The domain points at which to interpolate.
Type: double
Dimension: vector | matrix
method
The available options are:
'linear'
Returns the bilinear interpolation from the nearest neighbors.
'spline'
Returns the bicubic spline interpolation from the nearest neighbors.
Type: string
extrap
The available options are:
'extrap'
Allows extrapolation beyond the intervals.
'noextrap'
Does not allow extrapolation (default).
Type: string

Outputs

zi
The interpolated z values corresponding to (xi,yi) pairs.
Dimension: matrix

Examples

With 'linear' method:

x = [2, 5, 6, 10, 12, 17];
y = [10, 13, 17, 18, 23, 25, 29];
z = [98  184  214  328   386   528;
129  242  281  431   507   694;
170  319  370  568   668   915;
181  339  393  603   709   971;
232  435  504  774   910  1247;
253  474  549  843   991  1358;
294  551  638  980  1152  1579];
xi = [3, 5, 7, 11, 16];
yi = [11, 16, 21, 29]';
zi = interp2(x,y,z,xi,yi,'linear')
zi = [Matrix] 4 x 5
140.00000  203.33333  267.83333   394.33333   551.93333
206.41667  299.75000  394.25000   580.75000   813.35000
273.26667  396.60000  521.10000   767.60000  1075.20000
379.66667  551.00000  723.50000  1066.00000  1493.60000

With 'spline' method:

x = [2, 5, 6, 10, 12, 17];
y = [10, 13, 17, 18, 23, 25, 29];
z = [98  184  214  328   386   528;
129  242  281  431   507   694;
170  319  370  568   668   915;
181  339  393  603   709   971;
232  435  504  774   910  1247;
253  474  549  843   991  1358;
294  551  638  980  1152  1579];
xi = [3, 5, 7, 11, 16];
yi = [11, 16, 21, 29]';
zi = interp2(x,y,z,xi,yi,'spline')
zi = [Matrix] 4 x 5
138.57956  203.66379  268.77725   394.48736   553.65523
204.24151  299.32574  394.43920   580.14931   814.31718
271.79883  396.88307  521.99653   767.70664  1076.87451
377.91577  551.00000  724.11346  1065.82357  1494.99144