File Exchange

image thumbnail

tinterp - an alternative to griddata

version 1.0 (3.58 KB) by

Linear and quadratic interpolation for scattered data



No License

Provides linear and quadratic interpolation methods for functions defined on scattered 2D datasets.

The quadratic method in tinterp seems to be superior when compared to the cubic method in gridata.

Type "help tinterp" & "help tester"

Comments and Ratings (5)

Jo Williams

Three years later and I'm still using it, but this code falls over in Matlab 2012a because TSEARCH has been removed. The following substitution fixes it:

%i = tsearch(p(:,1),p(:,2),t,pi(:,1),pi(:,2));

i = tsearchn(p,t,pi);

DelaunayTri and pointLocation are suggested by the error message, and may provide a speed improvement, but since I've saved a load of triangles the old way I don't really want a major rewrite!


carlos lopez

I would like to have more information of the theory behind this. What it means that it is "quadratic"? Should it be exact for 2nd. degree functions? I tried this
X=[1:10 1:10];Y=[zeros(1,10) ones(1,10)];%Data points
f=100*(X').^2; %data points
triplot(tri,X,Y) %to interpret the case
fC=tinterp([X' Y'],tri,f,x,y,'quadratic');
plot(diff(fC));%should be linear if the interpolant is exact for 2nd degree

Apparently from this example the interpolant is C0 (i.e. continuous but not differentiable), but it is a little bit misleading what is meant by "quadratic".

I tried to contact the author before posting, but apparently changed addres. Thank you anyway for his contribution.

Jo Williams

Craig M.

I make hundreds of 2D interpolations for a given triangulation. This function is exactly what I need. Thx.

John D'Errico

An alternative to griddata - similar in speed when you add in the time for the triangulation.

The advantage of this code is if you already have a triangulation, then this saves the time to regenerate it. It also allows you to use a custom, non-delaunay triangulation - not an option at all for griddata.

A disadvantage of this code is it forces you to do the triangulation to call it. Its an unnecessary step for many people, so I'd probably be tempted to allow the user to not supply the triangulation, so if t is empty it could just call delaunay.

This code offers properties similar to griddata. It will not extrapolate beyond the convex hull of the data, Extrapolation is risky business of course, so thats not necessarily bad.

Good help, examples. The quadratic interpolant is an interesting idea.

MATLAB Release
MATLAB 6.5 (R13)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Win prizes and improve your MATLAB skills

Play today