AUTHOR: Darryl Morrell
SOURCE: Engineering Problem Solving with MATLAB LICENSE: [http://creativecommons.org/licenses/by-sa/3.0/ CC-BY-SA] ATTRIBUTION: This text adapted from the content with CC-BY license available at http://cnx.org/content/m13259/1.6/
You can use m-file scripts to automate computations. Almost anything typed at the command line can also be included in a m-file script. Lines in a m-file script are interpreted sequentially and the instructions are executed in turn. M-file scripts allow you to implement complex computations that cannot be readily achieved using commands at the command line. You can also create computational capabilities for other people to use.
M-file scripts interact with the current executing 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.
Comments document your code and help other users (and yourself several months down the road) understand how you have implemented your program. Comments begin with the character \%; any text in a line after the \% is ignored by the script interpreter.
To correctly execute a script, the script file environment must know the directory in which the script resides.