next up previous contents
Next: 3. More on matrices Up: 2. Plotting Previous: 2.1.3.7 Contour plots   Contents

2.2 Three-dimensional plots

MATLAB is capable of a large array of fancy plots including some really neat three-dimensional plots. In this section we'll try out several. To start, consider the last example in the preceding section. We made a contour plot of a surface. We can also visualize surface itself. Try this,
% Plotting in 3D
close all; clear all;
points = linspace(-2,2,40); % 40 equally spaced points between
[X Y] = meshgrid(points,points); % Create two arrays, x & y
Z = 1./exp((X-.5).^2+Y.^2)-1./exp((X+.5).^2+Y.^2);
surfc(X,Y,Z)
Figure 2.3 demonstrates the expected output.
Figure 2.3: Example of three-dimensional plotting.
\includegraphics[width=0.5\linewidth]{surfc.eps}
Try each of these in turn too.
surf(X,Y,Z)
surfl(X,Y,Z)
mesh(X,Y,Z)
meshz(X,Y,Z)
waterfall(X,Y,Z)
We can also plot 3D lines. Consider a helix oriented in the $x$-direction. Try this,
% 3D line plotting; a helix along x
close all; clear all;
x = linspace(0,8*pi,200); % 200 equally spaced points between 0 and 8pi
plot3(x,sin(x),cos(x))
xlabel('x')
ylabel('sin(x)')
zlabel('cos(x)')
grid on % Show a background grid
Now try axis equal. To see what other kinds of 3D plots MATLAB can do, type help graph3d and help specgraph. We'll come back to some advanced topics such as animation, vector fields, volumetric plots, etc., in Chapter 9.

Gus Hart 2005-01-28