In order to plot in three dimensions one need to specify a grid of points in the x-y domain; this is much like specifing the ordered pairs in the plane where points will be plotted. The Matlab command meshgrid achieves this as follows.
>>x=a:dc:b;
>>y=c:dy:d;
[X,Y]=meshgrid(x,y);
The last command creates two matrices X and Y of size length(y) by length(x) (row by column). The element by element correspondence between these matrices is the collection of ordered pairs forming the grid points for plotting. An explicit example shows how this is done:
» x=[1 2 3];
» y=[4 5 6 7];
» [X,Y]=meshgrid(x,y)
X =
1 2 3
1 2 3
1 2 3
1 2 3
Y =
4 4 4
5 5 5
6 6 6
7 7 7
Notice that X increases along the columns from left to right in the x variable; Y increases along the rows from top to bottom in the y variable. If a function is computed on this grid, say z=f(X,Y), then the command
>plot3(X,Y,z)
forms a linear plot much like that of the two dimensional plot command.
The plot3 command is very useful in plotting space curves. For example the helix is plotted with the commands
» t=0:pi/30:6*pi;
» plot3(cos(t),sin(t),t)

The commands used in 2d plots for titles, controling axis tick marks, axis labels, legend, etc all work the same in 3 dimensions and we need not discuss them here.
Matlab provides two key commands for plotting surfaces: mesh and surf. Mesh takes the 3-d data and creates a wire mesh through adjacent points. On the other hand, surf creates a mesh plot with the spaces between the lines, called patches, filled in according to a color scheme based on the z data. Here is an example
» x=0:pi/20:pi;
» y=x;
» [X,Y]=meshgrid(x,y);
» f=inline('sin(2*x).*cos(3/2*y)','x','y')
f =
Inline function:
f(x,y) = sin(2*x).*cos(3/2*y)
» %Note the function is vectorized
» subplot(1,2,1),mesh(X,Y,f(X,Y))
» title('A Mesh Plot')
» subplot(1,2,2),surf(X,Y,f(X,Y))
» title('A Surf Plot')

NOTE: Either of the above sub-figures can be viewed from different view points. On the tool bar select the button for 3-d rotation. This allows grabbing the axis with the mouse and rotating to a different view. This can also be achieved from the command line. Type: help view to find out how.
The color scheme for suface plots can be easily changes. Some built in color maps are: hot, cool, gray, copper, summer, winter,bone. Here is the above plot with different color schemes. You can achieve this by clicking on a subfigure and typing at the prompt
>>colormap(whatever you choose)
>>colorbar

The color bar depicts how Matlab associates a particular shade of copper with the numerical values of the function.
A shading effect in surf plots can be achieved; this controls how color is interpolated between the lines. The default is faceted (above figures) meaning a stained glass effect with constant color patches. Other possibilities are flat (lines removed but each piece has constant color) and interpolated (lines removed and color of each patch interpolated between the edges).
As an example, and using the same function as in previous examples.
» subplot(1,2,1),surf(X,Y,f(X,Y))
» colormap(bone)
» shading flat
» title('Flat Shading')
» subplot(1,2,2),surf(X,Y,f(X,Y))
» shading interp
» title('Interpolated Shading')

Given a function z = f(r,theta), one may desire a surface plot on a circular meshgrid. Combining the meshgrid command with a command to convert polar coordinates to rectangular this is easily achieved. The following example will get you started.
» [th,r]=meshgrid(0:pi/40:2*pi,0:0.05:1);
» [X,Y]=pol2cart(th,r);
» g=inline('r.^n.*sin(n*th)','r','th','n')
g =
Inline function:
g(r,th,n) = r.^n.*sin(n*th)
» surf(X,Y,g(r,th,5))
» hold on
» mesh(X,Y,-ones(size(X)))
» title('A Cylindrical Plot')

Given mesh data, contour plots can be generated using the command contour. For example:
» x=0:0.5:6;
» t=0:0.5:20;
» [X,T]=meshgrid(x,t);
» g=inline('cos(x-0.4*y).*exp(-0.4*x)','x','y')
g =
Inline function:
g(x,y) = cos(x-0.4*y).*exp(-0.4*x)
» contour(X,T,g(X,T))
» colorbar
» title('Damped Traveling Wave')
» xlabel('x')
» ylabel('t')
This generates the following figure, a spacially damped traveling wave.

Contours can be combined with surf and mesh plots, for example
» surfc(X,Y,g(X,Y))
% surfc or meshc are the commands
» xlabel('x')
» ylabel('t')
» colormap(bone)

Finally, the combination of patch shading and contour can be achieved with the command pcolor.
» x=0:0.5:6;
» t=0:0.5:40;
» [X,T]=meshgrid(x,t);
» pcolor(X,T,g(X,T))
» shading interp
» hold on
» contour(X,T,g(X,T),'k')
% the 'k' forces the contour lines to be in black
» colorbar
» title('Traveling Wave with pcolor')
» xlabel('x')
» ylabel('t')
