How to Extrapolate griddata for contour plot?

74 Ansichten (letzte 30 Tage)
UH
UH am 11 Nov. 2023
I have xy-grid with corresponding contour values which I intend to plot in a contour.
my x-grid and y-grid values are at dimensions 0:20:120 and 0:20:220, respectively.
load('xyref.mat')
I interpolated these values at grid of 10 units in xy direction using the contour value using meshgrid
load('contr.mat')
[x1,y1] = meshgrid(0:10:120, 0:10:220);
za = griddata(x,y,contr,x1,y1);
figure
[c,h] = contourf(x1,y1,za,'ShowText','on',FaceAlpha=1,EdgeAlpha=0.5,EdgeColor='k',LevelStep=5);
grid on
Now, at this point, I want to extrapolate these contour values to further 20 units range in both directions. I have already extracted these data of huge magnitude and it would take immense time in extrapolating these data. What I want to do is just linearly extrapolate these contours in the range -20 to 140 and -20 to 240 in x and y directions. Is there a way to extrapolate the griddata to those values?
Right now, the graph, when extrapolated gives nan values in the griddata and plots like this
[x1,y1] = meshgrid(-20:10:140, -20:10:240);
zb = griddata(x,y,contr,x1,y1);
figure
[c2,h2] = contourf(x1,y1,zb,'ShowText','on',FaceAlpha=1,EdgeAlpha=0.5,EdgeColor='k',LevelStep=5);
grid on
I hope I have explained my problem adequately. Your help in extrapolating griddata will be much appreciated. Thanks in advance and have a great weekend.

Akzeptierte Antwort

Sulaymon Eshkabilov
Sulaymon Eshkabilov am 11 Nov. 2023
Here you can find an appropriate 3rd party fcn called inpaint_nans() that can be employed to subs NaNs in zb. Note that the MATLAB fcn fillmissing() does the job partially.
clearvars; close all; clc
load('xyref.mat')
load('contr.mat')
[x1,y1] = meshgrid(0:10:120, 0:10:220);
za = griddata(x,y,contr,x1,y1);
figure
[c,h] = contourf(x1,y1,za,'ShowText','on',FaceAlpha=1,EdgeAlpha=0.5,EdgeColor='k',LevelStep=5);
grid on
[x1,y1] = meshgrid(-20:10:140, -20:10:240);
zb = griddata(x,y,contr,x1,y1);
zb1=fillmissing(zb, 'nearest'); % fillmissing() substitutes NaNs partially
zb2=inpaint_nans(zb,0); % Substitutes all NaNs linearly
figure
[c2,h2] = contourf(x1,y1,zb2,'ShowText','on',FaceAlpha=1,EdgeAlpha=0.5,EdgeColor='k',LevelStep=5);
grid on
  2 Kommentare
UH
UH am 11 Nov. 2023
This works. This solves my problem, thanks to you.
Sulaymon Eshkabilov
Sulaymon Eshkabilov am 11 Nov. 2023
Most welcome. Glad to be of help.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte


Version

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by