% 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. 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 -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 gridNow 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