MATLAB: How to plot a contour map on the surface of a 3-d surface

3d plots

The idea is similar to using "surf(X,Y,Z,C)" but I want contour lines in addition to the coloring provided by C. The contour lines need to correspond to f(x,y,z), not x, y, or z. If there is a non-toolbox specific answer, that would be great. Thanks.

Best Answer

A simple tricky I use sometimes is to use a colormap with a small number of colors.
[x,y] = meshgrid(linspace(-pi,pi,150));
z = cos(x).*cos(y);
c = sin(x).*sin(y);
surf(x,y,z,c,'FaceColor','interp','EdgeColor','none')
zlabel('cosine')
colormap(lines(7))
c = colorbar;
c.Label.String = 'sine';
view([-45 60])
This makes my CData variable look like what the contourf function would draw.