Matlab Scripts
Entering commands into the Command Window and executing them one at a time works fine if we only have a few commands to execute to solve a problem, but as our problems and their solutions get more complex it is critical to have a way to save, and edit our solution. We also may want to share our code with others who have a similar problem to solve. For these reasons and many others, we save our work in program scripts instead of just executing commands in the command window.
Matlab program scripts are similar but different from the user-defined functions that you wrote in earlier lessons. Scripts can be executed as stand-alone programs while functions must be called by other functions or scripts or from the command window. Also, functions have input parameters and return values, while stand-alone scripts do not.
Enter your script into an m-file editor just like the function definitions presented in an earlier module. Save the script with a descriptive name and then execute the script to see the results. Note: The Windows version of Matlab will only recognize filenames that do not contain spaces and whose first character is a letter of the alphabet, Therefore, make sure the name of the M-file is one word and doesn't start with 1, 2, 3, ~, _, etc.
Execute scripts by clicking the button,
selecting Debug->Run
from the menu, or by typing the name of the
script in the Command Window.