MATLAB: Get mesh from surf function

meshsurf

Is there a way to get the mesh which the function "surf" produces? By that I mean I need the usual mesh format which is a list of vertices and a list of faces.

Best Answer

Yes, the surf2patch command.
[x,y,z] = peaks(10);
h = surf(x,y,z);
[f,v,c] = surf2patch(h);
At this point:
  • v is a 100x3 array containing the 100 vertices
  • f is an 81x4 array containing indices into v for the 81 faces
  • c is an vector of the 100 data values which would be used for coloring the vertices