MATLAB: Finding the Meshgrid provided a surface.

meshgrid

Hi All, given a surface, is there anyway to find the underlying meshgrid of the surface. For example, I have a surface given by function Z that has been created in the following manner:
x = -4:0.4:4; y = -8:0.4:8; [X,Y] = meshgrid(x,y);
Z = comp_z(X,Y);
%Given just the surface, Z , is there a way to find the meshgrid that created it?

Best Answer

How are you given the surface? As a fig file? You could extract the X and Y indices of the surface:
x = -4:0.4:4;
y = -8:0.4:8;
[X,Y] = meshgrid(x,y);
Z = (X.*Y);
surf(X,Y,Z)
h = findobj('Type','Surface');
surfX = h.XData;
surfY = h.YData;
all(all(surfX==X))
ans =
1
all(all(surfY==Y))
ans =
1