Graphics Programs Reference
In-Depth Information
We describe more of MATLAB's graphics commands in Chapter 5.
For now, we content ourselves withdemonstrating ow to plot a pair of
expressions on the same graph.
Plotting Multiple Curves
Eachtime you execute a plotting command, MATLAB erases the old plot and
draws a new one. If you want to overlay two or more plots, type
hold on
.
This command instructs MATLAB to retain the old graphics and draw any
new graphics on top of the old. It remains in effect until you type
hold off
.
Here's an example using
ezplot
:
>> ezplot('exp(-x)', [0 10])
>> hold on
>> ezplot('sin(x)', [0 10])
>> hold off
>> title 'exp(-x) and sin(x)'
The result is shown in Figure 2-3 earlier in this chapter. The commands
hold
on
and
hold off
work withall graphics commands.
With
plot
, you can plot multiple curves directly. For example,
>> X = 0:0.1:10;
>> plot(X, exp(-X), X, sin(X))
Note that the vector of
x
coordinates must be specified once for eachfunction
being plotted.
Search WWH ::
Custom Search