You can use MATLAB scripts to automate computations. Almost anything typed at the command line can also be included in a MATLAB program. Lines in a MATLAB script are interpreted sequentially and the instructions are executed in turn. This simplifies repetitive computations. This allows you to create complex computations that cannot be readily implemented using commands at the command line. You can also create computational capabilities for other people to use.
MATLAB scripts are text files and can be edited by any text editor. Any script should run the same on any computer running MATLAB regardless of its operating system. Script files must have an extension of ".m" and be in a directory that MATLAB knows about.
MATLAB scripts interact with the current MATLAB environment. Variables set before the script is executed can affect what happens in the script. Variables set in the script remain after the script has finished execution.
One way to edit MATLAB scripts is to use the built-in editor. The editor has some features that make editing MATLAB scripts easier. The editor is integrated with the debugger which makes finding and correcting errors in your scripts easier. More detailed information about editing scripts can be found at
Mathworks Matlab Tutorial-Creating Scripts with MATLAB Editor/Debugger.
Use comments to remind you and help other users understand how you have implemented your program. Comments begin with the character %.
M-file names should begin with a letter and only contain letters and numbers. Any other characters (space, dash, star, slash, etc.) will be interpreted by MATLAB as operations on variables and will cause errors. Also, M-file names should not be the same as variables in the workspace, since MATLAB will not be able to differentiate between the file name and the variable.