1D interpolation with non-monotonic scattered data
29 ビュー (過去 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!
0 件のコメント
採用された回答
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 件のコメント
その他の回答 (2 件)
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
0 件のコメント
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).
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Matrices and Arrays についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!