Page 20 -
P. 20
1.3.2 Labeling a Graph
To add labels to your graph, the functions xlabel, ylabel, and title can
be used as follows:
xlabel('x-axis')
ylabel('y-axis')
title('points in a plane')
If you desire to add a caption anywhere in the graph, you can use the MAT-
LAB command gtext('caption') and place it at the location of your
choice, on the graph, by clicking the mouse when the crosshair is properly
centered there.
1.3.3 Plotting a Point in 3-D
In addition to being able to plot points on a plane (2-D space), MATLAB is
also able to plot points in a three-dimensional space (3-D space). For this, we
utilize the plot3 function.
Example 1.6
Plot the point P(3, 4, 5).
Solution: Enter the following commands:
x1=3; y1=4; z1=5;
plot3(x1,y1,z1,'*')
You can also plot multiple points in a 3-D space in exactly the same way as
you did on a plane. Axis adjustment can still be used, but the vector input
into the axis command must now have six entries, as follows:
axis([xmin xmax ymin ymax zmin zmax])
You can similarly label your 3-D figure using xlabel, ylabel, zlabel,
and title.
1.4 M-files
In the last section, we found that to complete a figure with a caption, we had
to enter several commands one by one in the command window. Typing
© 2001 by CRC Press LLC