Depending on how you plotted the 3D surface, you may already have those coordinates before the plot is produced. For example, x, y, and z are the grid coordinates in this surface,
If you do not have access to those coordinates, for example, in surf(Z), you can extract them from the surface object handle,
coordinates = [h.XData(:), h.YData(:), h.ZData(:)];
and if you want the color data, h.CData(:).