Take the 2-minute tour ×

I have a NxN grid of values and a 2xM list of x,y data points to be interpolated onto that grid (obtained from the output of countour on a similar grid of values).

How do I do this in MATLAB?

This is sort of the reverse of the problem that griddata, TriScatteredInterp and perhaps more appropriately, inpaint_nan solves (i.e. scattered points to generate a grid).

share|improve this question

1 Answer 1

up vote 2 down vote accepted

Use interp2, the tool designed to do exactly that.

share|improve this answer
Hmm, you're right. I had looked at interp2 but the documentation implied that the inputs all had to be grids and if they weren't then they would be converted internally to grids using meshgrid - For some reason I had it in my head that meshgrid required monotonic data inputs. –  Brendan Jun 9 '11 at 12:10
Much of the time, interp2 is used to do exactly that. You start with a 100x100 array, and you wish to resample it to become a 500x500 array. Use interp2, on a set of points generated by meshgrid. But nothing says that interp2 cannot interpolate a single arbitrary point, or a set of independent, scattered points. Any set of (xi,yi) pairs can be interpolated as long as what you are interpolating itself lives on a rectangular grid. –  user85109 Jun 9 '11 at 12:30
It is when the data that forms the interpolant itself is scattered that you must resort to tools like griddata, TriScatteredInterp, radial basis functions, gridfit, etc. inpaint_nans arguably lies somewhere in the middle, in the sense that the data lies on a regular lattice, but you wish to fill in the holes in that lattice to make it complete. –  user85109 Jun 9 '11 at 12:34

Your Answer


