matlab interp2 gives an error’monotonically increasing’

The function griddata is your friend for these tasks, It uses scatteredInterpolant under the hood, but in my opinion is more user friendly.

Keeping the same example code you gave, replacing the last line with:

>> need_y = griddata(x_all,z_all,y_all,want_x, want_z)
need_y =

The function can take vector inputs for want_x and want_z and return a vector output of need_y if you need to query more than one point.

You can also specify the interpolation method (linear, cubic, etc …).

And just to make sure it worked as desired:

>> F = scatteredInterpolant(x_all.', z_all.', y_all.', 'linear');   %NOT y_all, z_all
need_y = F(want_x, want_z)
need_y =
         0.329506024096386 % same result, yay!

For more details about using griddata, you can have a look at my answer to this question extremely similar to yours (just worded a bit differently): Interpolation between two curves (matlab)

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top