You can put a sequence of MATLAB commands into a simple script file as an alternative to typing the sequence again. To do this, select either 'File/New' or the icon that looks like a document. The MATLAB Editor opens and you can enter MATLAB commands.
Try this one:
|
x = 0: .01 : 5;
y = sin (x) .* cos (5*x); plot(x, y) |
Now save the file. You are asked for a file name. Try the name sines. MATLAB will store this file with the name sines.m. This m extension indicates a MATLAB file.
You can use your scipt at the command prompt. Just type sines
or
sines.m, and MATLAB runs your script.
Here is a slightly more complicated script. It contains MATLAB
comments, as well as the MATLAB commands for text input, text output,
and pause.
| % MATLAB example script
% produces a plot based on user input % get interval for x-axis
% compute x and y arrays, then display them
% create a pause
% create a plot of y as a function of x
|
Some rules about MATLAB script files