Graphics Programs Reference
In-Depth Information
asawordprocessor,orconvertyourresultstoHTMLformat,bytheprocedures
described in Chapter 10. But to share your results more informally, you can
give someone else your M-file, assuming that person has a copy of MATLAB
on which to run it, or you can provide the output you obtained. Either way,
you should remember that the reader is not nearly as familiar with the M-file
as you are; it is your responsibility to provide guidance.
You can greatly enhance the readability of your M-file by including frequent
comments. Your comments should explain what is being calculated, so that
the reader can understand your procedures and strategies. Once you've done
the calculations, you can also add comments that interpret the results.
If your audience is going to run your M-files, then you should make liberal
use of the command pause . Eachtime MATLAB reaches a pause statement,
it stops executing the M-file until the user presses a key. Pauses should be
placed after important comments, after eachgraph, and after critical points
where your script generates numerical output. These pauses allow the viewer
to read and understand your results.
Diary Files
Here is an effective way to save the output of your M-file in a way that others
(and you!) can later understand. At the beginning of a script M-file, such as
task1.m , you can include the commands
delete task1.txt
diary task1.txt
echo on
The script M-file should then end with the commands
echo off
diary off
The first diary command causes all subsequent input to and output from
the Command Window to be copied into the specified file — in this case,
task1.txt . The diary file task1.txt is a plain text file that is suitable for
printing or importing into another program.
By using delete at the beginning of the M-file, you ensure that the file only
contains the output of the current script. If you omit the delete command,
thenthe diary commandwilladdanynewoutputtotheendofanexistingfile,
and the file task1.txt can end up containing the results of several runs of
the M-file. (Putting the delete command in the script will lead to a harmless
Search WWH ::




Custom Search