next up previous contents
Next: 3. More on matrices Up: 2. Plotting Previous: 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);
Figure 2.3 demonstrates the expected output.
Figure 2.3: Example of three-dimensional plotting.
Try each of these in turn too.
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
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