2.2
X-Y PLOTS AND ANNOTATIONS
The plot command generates a linear x-y plot.
There are three variations of the
plot command.
(a)
plot(x)
(b)
plot(x, y)
(c)
plot(x1, y1,
x2,
y2,
x3,
y3, ..., xn,
yn)
If x is a vector, the command
plot(x)
will produce a linear plot of the elements in the vector x as a function of the
index of the elements in x.
MATLAB
will connect the points by straight lines.
If x is a matrix, each
column will be plotted as a separate curve on the same
graph.
For example, if
x
= [ 0 3.7 6.1 6.4 5.8 3.9 ];
then,
plot(x)
results in the graph shown in
Figure 2.1
.
If x and y are vectors of the same length, then the command
plot(x, y)
plots the elements of x (x-axis) versus the elements of y (y-axis).
For example,
the MATLAB commands
t = 0:0.5:4;
y = 6*exp(-2*t);
plot(t,y)
will plot the function
y t
e
t
( )
=
−
6
2
at the following times: 0, 0.5, 1.0, …, 4 .
The plot is shown in
Figure 2.2
.
To plot multiple curves on a single graph, one can use the plot command
with multiple arguments, such as
plot(x1,
y1,
x2,
y2,
x3,
y3, ..., xn, yn)
© 1999 CRC Press LLC