2D Interpolation & Extrapolation with non linear Sample grid points and nan
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Laurent Davenne
am 23 Jun. 2022
Kommentiert: Voss
am 24 Jun. 2022
Hi,
I have this 2D map wich I would like to interpolate to make square but also extrapolate.

interp2 does seem to work with nan inputs as it just returns same nan as output.
V=[1.029 1.000 1.060 1.048 nan nan nan
1.049 1.014 1.038 1.092 1.075 nan nan
nan 1.039 1.079 1.036 1.029 1.003 nan
nan nan 1.042 1.072 1.000 0.998 1.028
nan nan nan 1.038 1.024 1.076 1.022
nan nan nan nan 1.082 0.997 1.011];
X=[8 10 15 25 35 45 52];
Y=[5 10 16.25 22.5 28.75 35];
Xq=ones(numel(Y),numel(X)).*X;
Yq=ones(numel(Y),numel(X)).*Y';
Z=interp2(X,Y,V,Xq,Yq)
I tried some inpaint functions from the community but none of them seems to be made to work with non linear sample grid points (0 2 7 17...).
I am open to suggestions
Thanks in Advance
Laurent
4 Kommentare
Akzeptierte Antwort
Voss
am 24 Jun. 2022
Bearbeitet: Voss
am 24 Jun. 2022
V = [ ...
1.029 1.000 1.060 1.048 nan nan nan
1.049 1.014 1.038 1.092 1.075 nan nan
nan 1.039 1.079 1.036 1.029 1.003 nan
nan nan 1.042 1.072 1.000 0.998 1.028
nan nan nan 1.038 1.024 1.076 1.022
nan nan nan nan 1.082 0.997 1.011]
X = [8 10 15 25 35 45 52]; % using the X and Y from your code rather than
Y = [5 10 16.25 22.5 28.75 35]; % from your image, which are 5 less
% make a scatteredInterpolant of the points where V is non-NaN
[XX,YY] = meshgrid(X,Y);
idx = ~isnan(V(:));
I = scatteredInterpolant(XX(idx),YY(idx),V(idx));
% interpolate/extrapolate to all points
Z = reshape(I(XX,YY),numel(Y),[])
% visualization
x_lim = [min(X) max(X)];
y_lim = [min(Y) max(Y)];
z_lim = [min(Z(:)) max(Z(:))];
temp = {V Z};
names = {'V' 'Z'};
for ii = [1 2]
subplot(2,1,ii)
surface(XX,YY,temp{ii},'FaceColor','interp')
set(gca(),'YDir','reverse')
view(2)
xlim(x_lim);
ylim(y_lim);
xlabel('X');
ylabel('Y');
colorbar();
caxis(z_lim);
title(names{ii});
end
2 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Interpolation finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
