%% Calculate Patch Data from Surface Data
% Use the sphere command to generate the XData, YData, and ZData of a surface. Then, calculate the patch data. Pass the ZData (z) to surf2patch as both the third and fourth arguments - the third argument is the ZData and the fourth argument is taken as the CData. You must do this since the patch command does not automatically use the z-coordinate data for the color data, as does the surface command.
% Since patch is a low-level command, you must set the view and shading to produce the same results produced by the surf command.

[x,y,z] = sphere; 
figure
patch(surf2patch(x,y,z,z)); 
shading faceted; 
view(3)

% Copyright 2015 The MathWorks, Inc.