Commit 39f7f4a7 authored by Laurent Belcour's avatar Laurent Belcour

Fixing the Matlab interpolator to handle domain boundary.

parent f519aa73
......@@ -123,7 +123,7 @@ vec data_interpolant::value(vec ax) const
// Evaluate the matlab routine
std::stringstream cmd;
cmd << "y = griddatan(X(:, 1:" << dimX() <<"), Y(:, 1), x);";
cmd << "y = griddatan(X(:, 1:" << dimX() <<"), Y(:, 1), x, 'linear');";
engEvalString(ep, cmd.str().c_str());
// Get results and copy it
......@@ -131,6 +131,21 @@ vec data_interpolant::value(vec ax) const
double* y_val = (double*)mxGetData(y);
memcpy(&res[0], y_val, dimY()*sizeof(double));
// Fail safe: if the query point is outside of the convex hull of the
// data, rerun the algorithm using a nearest option.
if(isnan(res[0]))
{
cmd.str(std::string());
cmd << "y = griddatan(X(:, 1:" << dimX() <<"), Y(:, 1), x, 'nearest');";
engEvalString(ep, cmd.str().c_str());
// Get results and copy it
y = engGetVariable(ep, "y") ;
double* y_val = (double*)mxGetData(y);
memcpy(&res[0], y_val, dimY()*sizeof(double));
}
return res;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment