1D interpolation with non-monotonic scattered data

28 次查看(过去 30 天)
I cant figure out how do 1D interpolation with scattered data. I know how to get it working with 2D interpolation, but scatteredinterpolant only works with 2D or more. Thank you for your help!

采纳的回答

Andrei Bobrov
Andrei Bobrov 2014-10-20
编辑:Andrei Bobrov 2014-10-20
small example:
x = rand(30,2); % you data
x1 = sortrows(x,1);
F = griddedInterpolant(x1(:,1),x1(:,2));
out = F(xinput);
  2 个评论
Kim
Kim 2014-10-20
I just tried it and I got the following message: Error using griddedInterpolant The grid vectors are not strictly monotonic increasing.

请先登录,再进行评论。

更多回答(2 个)

Riley
Riley 2016-10-5
Just ran into this same issue, however the solution posted seems to avoid tackling an important detail here- griddedInterpolant, unlike scatteredInterpolant, doesn't remove repeated index points (at least, on 2015a). For example:
x = rand(30,2); % clean data
x1 = sortrows(x,1);
F = griddedInterpolant(x1(:,1),x1(:,2)); % this is fine
x_repeat = x1(:,1);x_repeat(2) = x_repeat(3); % introduce a repeated index point
F = griddedInterpolant(x_repeat,x1(:,2)); %produces an error
compare that to the scatteredInterpolant class-
x = rand(30,3); % clean data
x1 = sortrows(x,1);
x_repeat = x1(:,1:2);x_repeat(2,:) = x_repeat(3,:); % introduce a repeated index point
F = scatteredInterpolant(x_repeat,x1(:,3)); %rather than throwing an error, shows a warning and cleans your data for you
however, as scatteredInterpolant requires at least 2 dimensions for its indices, this doesn't work for 1d interpolation. Clearly at this point you can add your own cleaning method, but if you are using this class chances are you are trying to avoid writing that sort of code in the first place. As such, here's a hack I used to use the scatteredInterpolant cleaning method on a 1d data set-
xi = rand(30,1);%indices
x = sort(xi);
v = rand(30,1);% values
xq = [0.5 0.6];% query indices
x(2) = x(3);% the repeated index
Fs = scatteredInterpolant(x*ones(1,2),v);%make 1d into 2d
%note that the sane thing to do doesn't work: vq = Fs(xq'*ones(1,2)) produces an empty vector
F = griddedInterpolant(Fs.Points(:,1),Fs.Values);
vq = F(xq);
this produces plenty of warnings and will make you feel bad, but if you want a quick solution it will work

AlexL
AlexL 2022-7-19
I was also curious to solve this issue.
I wrote a short function that was helpful for me. You're welcome to try it (attached).

类别

Help CenterFile Exchange 中查找有关 Matrices and Arrays 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by