How to Extrapolate griddata for contour plot?

조회 수: 72 (최근 30일)
UH
UH 2023년 11월 11일
댓글: Sulaymon Eshkabilov 2023년 11월 11일
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.

채택된 답변

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2023년 11월 11일
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
UH
UH 2023년 11월 11일
This works. This solves my problem, thanks to you.
Sulaymon Eshkabilov
Sulaymon Eshkabilov 2023년 11월 11일
Most welcome. Glad to be of help.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Interpolation에 대해 자세히 알아보기

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by