MATLAB: How to plot interpolated grid data and original datapoint set in the same plot

grid datainterpolation

Hi,
After creating a grid data series (Data Terrain Model) from interpolating contour lines, I would like to plot everything on the same layer, but I am not sure if it is possible in matlab. Here is the gist of what I've done:
[xi,yi] = meshgrid(Xmin:res:Xmax, Ymin:res:Ymax);
f = scatteredInterpolant(contour_grid.X,contour_grid.Y,contour_grid.Z);
zi= f(xi,yi)
Xi=[xi(:); contour_grid.X];
Yi=[yi(:); contour_grid.Y];
Zi=[zi(:); contour_grid.Z];
Is there a way to plot Xi, Yi, and Zi? I'd have to turn these arrays back into grids to be able to use mesh(X,Y,Z) but I am struggling to write how to do that.
Has anyone ever had to do that?
Thanks,

Best Answer

You can always simply plot all your points:
plot3(Xi,Yi,Zi,'r.')
Or with scatter:
scatter(Xi,Yi,32,Zi,'filled')
But to me this seems to be more interesting:
pcolor(xi,yi,zi),
% shading flat % or interp adjust shading to fit taste
hold on
plot(xi,yi,'k.','markersize',6)
scatter(contour_grid.X,contour_grid.Y,23,contour_grid.Z,'filled')
Or you could compare contour-plots:
Levels = linspace(min(Zi(:)),max(Zi),10);
contour(Xi,Yi,Zi,Levels,'k')
hold on
tri=delaunay(contour_grid.X,contour_grid.Y);
[c,h]=tricontour(tri,contour_grid.X,contour_grid.Y,contour_grid.Z,Levels);
plot(contour_grid.X,contour_grid.Y,'k.')
You can find the tricontour function on the file exchange: TRICONTOUR
HTH