Graphics Programs Reference
In-Depth Information
Let's analyze this solution. We start by defining the values to use on the x
axis. The command close all removes all existing graphics windows; axes
starts a fresh, empty graphics window; and hold on lets MATLAB know that
we want to draw several curves on the same set of axes. The lines between
for and end constitute a for loop , as described above. The important part
of the loop is the plot command, which plots the desired sine curves. We
inserted an echo off command so that we only see the loop commands once
in the Command Window (or in a diary file). Finally, we turn echoing back on
after exiting the loop, use hold off to tell MATLAB that the curves we just
graphed should not be held over for the next graph that we make, title the
figure, and instruct MATLAB to pause so that the viewer can see it.
Pretty Printing
If s is a symbolic expression, then typing pretty(s) displays s in
prettyprint format,whichusesmultiplelinesonyourscreentoimitatewritten
mathematics.Theresultisoftenmoreeasilyreadthanthedefaultone-lineout-
put format. An important feature of pretty is that it wraps long expressions
to fit within the margins (80 characters wide) of a standard-sized window. If
your symbolic output is long enough to extend past the right edge of your win-
dow, it probably will be truncated when you print your output, so you should
use pretty to make the entire expression visible in your printed output.
A General Procedure
In this section, we summarize the general procedure we recommend for using
the Command Window and the Editor/Debugger (or your own text editor) to
make a calculation involving many commands. We have in mind here the case
when you ultimately want to print your results or otherwise save them in
a format you can share with others, but we find that the first steps of this
procedure are useful even for exploratory calculations.
1. Create a script M-file in your current working directory to hold your com-
mands. Include echo on near the top of the file so that you can see which
commands are producing what output when you run the M-file.
2. Alternate between editing and running the M-file until you are satisfied
that it contains the MATLAB commands that do what you want. Remem-
ber to save the M-file each time between editing and running! Also, see
the debugging hints below.
Search WWH ::




Custom Search