interp2() 'monotonically increasing' error
1 次查看(过去 30 天)
显示 更早的评论
I have many lines that represent a "z" value and want to interpolate at a specific value between them, at a specific x-axis location, to get the y-value. I'm trying interp2() but it throws a 'monotonically increasing' error.
The dataset below is a subset. I broke it out into xyz-1 and xyz-2 just for easy plotting in this question (i.e., making a repeatable example). How can I fix my interp2() or the inputs?
x1 = [0.02, 0.048, 0.108, 0.196, 0.279, 0.401];
y1 = [0.583, 0.43, 0.32, 0.279, 0.262, 0.259];
z1 = [50, 50, 50, 50, 50, 50];
x2 = [0.02, 0.048, 0.108, 0.196, 0.279, 0.401];
y2 = [0.747, 0.591, 0.435, 0.357, 0.326, 0.305];
z2 = [35, 35, 35, 35, 35, 35];
x_all = [x1, x2];
y_all = [y1, y2];
z_all = [z1, z2];
plot(x1, y1, 'blue', 'DisplayName', 'z1')
hold on
plot(x2, y2, 'magenta', 'DisplayName', 'z2')
xlabel('x')
ylabel('y')
legend
want_x = 0.2;
want_z = 40;
need_y = interp2(x_all, y_all, z_all, want_x, want_z, 'linear')
Error:
Error using griddedInterpolant
The grid vectors must be strictly monotonically increasing.
Error in interp2>makegriddedinterp (line 228)
F = griddedInterpolant(varargin{:});
Error in interp2 (line 128)
F = makegriddedinterp({X, Y}, V, method,extrap);
0 个评论
采纳的回答
Walter Roberson
2020-11-6
编辑:Walter Roberson
2020-11-6
interp2() is only for two-dimensional interpretation over a grid, not for interpolation of vectors. You need something like
F = scatteredInterpolant(x_all, z_all, y_all, 'linear'); %NOT y_all, z_all
need_y = F(want_x, want_z);
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Surface and Mesh Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!