Hello,
I am trying to extrapolate a 2D surface. The full code, including raw data, that I am working with is at the end of this message.
Extrapolation:
I used griddedinterpolant because MATLAB 2013 documentation indicates that it performs the extrapolation automatically (only for 2013):
http://www.mathworks.com/help/matlab/ref/griddedinterpolantclass.html
I am hoping to perform the extrapolation over the range of coordinates indicated by [extrpl_range_x, extrpl_range_y]. For generating the rectangular grid, I have used meshgrid or ndgrid:
Meshgrid: http://www.mathworks.com/help/matlab/ref/meshgrid.html
Ndgrid: http://www.mathworks.com/help/matlab/ref/ndgrid.html
You can copy and paste all the code into a script window and run the code to see for yourself what the problem is. MATLAB 2013 is required for this.
PROBLEM:
a. I am not getting extrapolation in the corners. The original data was missing the corners, but I was hoping that extrapolated mesh would give a rectangular shape to fill in these corners. This does not appear to be happening
b. It seems like ndgrid is producing a rotated map.
Questions:
For a: Is there a problem with the rectangular coordinates  ndgrid?
For b: Is there a mistake with the extrapolation commands?
X
CODE:
num_linrly_spcd_pts=33; %linearly spaced points for linspace command
methd='natural'; %method of griddata interpolation; options: v4, cubic, natural, linear
methd2='nearest'; %method of griddedInterpolant interpolation; options: spline, cubic, nearest, linear
extrpl_range_x=8:50; %xrange over which extrapolation is to be performed
extrpl_range_y=10:50; %yrange over which extrapolation is to be performed
% Loading data:
X(:,1) = [7 17 29 41 0 45 7 17 29 41 0 45 7 17 29 41]; %X coordinates of map
X(:,2) = [17 17 17 17 23 23 28 28 28 28 33 33 38 38 38 38]; %Y coordinates of map
V = [1659 1160 2147 1392 1568 2444 1264 1505 1819 1790 1347 708 1404 1680 845]; %Values of 2D function
xlin = linspace(min(X(:,1)),max(X(:,1)),num_linrly_spcd_pts); %generate equally spaced x coordinate vector with 33 equally spaced points
ylin = linspace(min(X(:,2)),max(X(:,2)),num_linrly_spcd_pts); %generate equally spaced y coordinate vector with 33 equally spaced points
[Xlin,Ylin] = meshgrid(xlin,ylin); %Produce a full grid of x and y coordinates, which are the 33 generated equally spaced points
% Performing interpolation:
ZZ = griddata(X(:,1),X(:,2),V,Xlin,Ylin,methd); %perform griddata interpolation using specified method
% Plot interpolated mesh:
fig2=figure('Color',[1 1 1]);
efg=mesh(Xlin,Ylin,ZZ); %plot the interpolated data
axis tight; hold on
axis([10 50 10 40 min(V) 30000]);
hold on
az = 0; el = 90;view(az, el);
colorbar('location', 'EastOutside')
% % EXTRAPOLATION SECTION:
% % NDGRID APPROACH
% [Xlin3,Ylin3] = ndgrid(xlin,ylin);
% F = griddedInterpolant(Xlin3,Ylin3,ZZ,methd2);
% [x_qq,y_qq] = ndgrid(extrpl_range_x,extrpl_range_y);
% Vqq2 = F(x_qq,y_qq);
% % MESHGRID APPROACH
Xlin2=Xlin';Ylin2=Ylin';ZZ=ZZ';
F = griddedInterpolant(Xlin2,Ylin2,ZZ,methd2); %spline, cubic, linear, nearest
[x_q,y_q] = meshgrid(extrpl_range_x,extrpl_range_y);
x_q = x_q'; y_q = y_q';
Vqq1 = F(x_q,y_q);
% % Plotting extrapolated mesh:
fig4=figure('Color',[1 1 1]);
efg=mesh(x_q,y_q,Vqq1); %plot the extrapolated mesh  MESHGRID APPROACH
%efg=mesh(x_qq,y_qq,Vqq2); %plot the extrapolated mesh  NDGRID APPROACH
axis tight; hold on
axis([10 50 10 40 min(V) 40000]);
hold on
az = 0; el = 90;view(az, el);
colorbar('location', 'EastOutside')
