MATLAB: GriddedInterpolant bug

buggriddedinterpolant

There is a bug with the griddedInterpolant function with nearest and linear methods. If the query set contains any out-of-range values, the entire evaluated set is NaN, not just the results corresponding to the out-of-range queries.
In contrast, the griddedInterpolant with cubic interpolation method returns NaN for only out-of-range queries and correctly evaluates the in-range queries.
This is an problem for me because I'd like to use the linear method. I'm currently filtering out the out-of-range values from the query before processing, but the best solution would be to get the linear griddedInterpolant to work as it should. How should I fix it?
This bug is demonstrated by the following example script:
[X,Y,Z] = ndgrid(1:10,1:10,1:10);
V = X.^.5 + Y.^.5 + Z.^.5;
nearestInterp = griddedInterpolant(X,Y,Z,V,'nearest');
linearInterp = griddedInterpolant(X,Y,Z,V,'linear');
cubicInterp = griddedInterpolant(X,Y,Z,V,'cubic');
splineInterp = griddedInterpolant(X,Y,Z,V,'spline');
[Xq,Yq,Zq] = ndgrid(0:.5:10,0:.5:10,0:.5:10);
Vq_nearest = nearestInterp(Xq,Yq,Zq);
Vq_linear = linearInterp(Xq,Yq,Zq);
Vq_cubic = cubicInterp(Xq,Yq,Zq);
Vq_spline = splineInterp(Xq,Yq,Zq);
Thanks, Nick

Best Answer

This behavior was fixed in R2012a. If you are current on SMS, you can download R2012a or R2012b for free.
Related Question