MATLAB: ScatteredInterpolant with extrapolation method set to none doesn’t give NaN results

MATLAB

Why does the "scatteredInterpolant" function give results outside the domain even when the extrapolation method is set to none? Shouldn't it be NaN if it isn't extrapolating?

Best Answer

An extrapolation method of none means "Any queries outside the convex hull of Points return NaN."
It is possible that the point being provided is outside the domain but still within the convex hull.
There is currently no way to use "scatteredInterpolant" with a more defined a boundary.
Workaround:
Take the output of the "scatteredInterpolant" and put it through an if statement that checks if it is within the boundary. A good way to get a more defined boundary is to use the "boundary" function.
 
>> F = scatteredInterpolant(xdata, ydata, vals,'natural','none');
>> DT = delaunayTriangulation(xdata, ydata);
>> b = boundary(xdata, ydata);
>> out = F(x, y);
>> if ~inpolygon(x, y, DT.Points(b,1),DT.Points(b,2))
>> out = NaN;
>> end
This sets "out" to be NaN when it is outside the boundary, even if it is inside the convex hull
A more detailed example can be found inside the attached file.