Surf2patch Matlab Official

If you’ve ever worked with 3D graphics in MATLAB, you’re likely familiar with the surf function. It’s great for creating shaded surface plots. But what if you need more control? What if you want to manipulate the faces and vertices directly, combine multiple surfaces, or export your plot to another format?

% Display as a patch figure; patch('Faces', f, 'Vertices', v, ... 'FaceColor', 'interp', ... 'EdgeColor', 'none', ... 'FaceLighting', 'gouraud'); surf2patch matlab

The result looks identical to a surf plot, but now you have direct access to f and v . Here’s something less documented: surf2patch can also return face vertex colors (CData) from a surface: If you’ve ever worked with 3D graphics in

% Add some lighting for drama camlight headlight; lighting gouraud; axis equal; colorbar; What if you want to manipulate the faces

% Create surface data [X,Y,Z] = peaks(30); % Convert to patch format [f,v] = surf2patch(X,Y,Z);