Loops
A loop specifies that a command or group of commands should be repeated several times
The easiest way to create a loop is to use a for statement.
f = 1;
for n = 2:10
f = f*n;
end
f
use a semicolon to suppress intermediate output within the loop
To see the final output, we then needed to type f after the end of the loop.
Diary Files
The first diary command causes all subsequent input to and output from the Command Window to be copied into the specified file
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, then the diary command will add any new output to the end of an existing file and can end up containing the results of several runs of
the M-file
Mention at the starting
delete task1.txt
diary task1.txt
echo on
The script M-file should then end with the commands
echo off
diary off
You can also get extraneous output in a diary file if you type CTRL+C to halt a script containing a diary command. If this happens, you should type diary off in the Command Window before running the script again.
No comments:
Post a Comment