MATLAB: [interp2] Different interpolation methods in each dimension.

interp2interpolation method

I am looking for a way to use interp2 where for speed the interpolation method is different in each dimension. E.g. spline interpolation in column and linear in row. If possible I want to work within the existing framework, but since griddedInterpolant is a built-in method I am not sure this is possible. I can think of a number of instances where this capability in interp2 or interpn would be useful.

Best Answer

Sorry, but while this could be faster IF you wrote it from scratch, it will probably not be so in practice, IF you tried to do it by some means. Anyway, you cannot tell interp2 to use different orders of interpolant in each dimension.
That does not mean it is impossible. It is in fact doable using spapi to create the interpolant.
x = -2:.5:2;
y=-1:.5:1;
[xx, yy] = ndgrid(x,y);
z = sin(xx+yy);
sp = spapi({2,4},{x,y},z);
fnplt(sp)
view(4,11)
That interpolant was linear in x, and cubic in y.
HOWEVER, note what appear to be scallops in the surface. These are indeed present in the interpolated surface, and are an artifact of interpolation. Note that those scallop artifacts are in fact considerably more obvious when a fully bilinear interpolant is applied to the same problem. This happens because a bilinear interpolant is not in fact quite as linear as you might think.
So, is this interpolant faster than interp2? Not so.
timeit(@() interp2(x,y,z',.15,.25,'spline'))
ans =
0.00049108
timeit(@() fnval(sp,[.15;.25]))
ans =
0.0013427
So for the spapi based spline interpolant that was linear in x and cubic in y, spapi was actually nearly 3 times slower than the full 2-d spline interp2 call.
Sorry. If you want significantly faster code, you would need to write it from scratch, and NOT in MATLAB.