MATLAB: How to set constraints of griddata results are all non-negative

griddata non-negative

I use the griddata function in matlab, but after the interpolation, the value of some points is less than 0. Is there any way to control the range of interpolation results?
That is to say, the results I want are all non-negative, but the results obtained after interpolation are somewhat less than 0.
Is there any way to set constraints?

Best Answer

"Is there any way to control the range of interpolation results?"
You could simply adjust the output data yourself:
A = max(0,min(100,A))
Depending on your data values you might be able to change the input data values and/or the interpolation method, e.g. if you used a spline or similar, then you might be able to change for linear interpolation.
Related Question