MATLAB: How to add 3D labeled contours to a surface plot

contourlegendlevellistMATLABsurfc

How can I add 3D labeled contours to a surface plot?

Best Answer

The functions 'surf', 'contour3', and 'clabel' can be used together to produce an elegant plot. The example below demonstrates how:
>> figureHandle = figure;
>> axesHandle = axes(figureHandle);
>> hold on
>> surfaceHandle = surf(axesHandle, peaks,'linestyle','none','FaceAlpha',0.7);
>> [contourMatrix, contourHandle] = contour3(axesHandle, peaks,'k');
>> hold off
>> clabel(contourMatrix, contourHandle)