Script files, also called M- files as they
have extension
.m, make MATLAB programming much more efficient than
entering individual commands at the command prompt. A script file
consists of MATLAB commands that together perform a specific task.
The M-file is a text file which can be created and edited by any
plain text editor like Notepad, emacs or the built-in MATLAB
editor. To create a script in MATLAB use:
File - New - M -File from the menu. An example script
is shown below.
Example 1
Our first script.
n = 0:pi/100:2*pi; %create an index vector
y = cos(2*pi*n); %create a vector y
plot(n,y); %plot y versus n
As shown above the %-sign allows for comments. Saving the script as
foo.m it can be executed as foo from the command prompt or by clicking the run
button in the MATLAB editor. Script files are very practical and should be the preferred alternative compared to the command prompt
in most cases.




