Introduction to MATLAB & SIMULINK: A Project Approach, Third Edition

As noted at the beginning of this chapter, MATLAB is not only a numerical program for evaluating formulas, but is a programming language in itself. This means that, besides the commands mentioned previously, MATLAB includes such program language constructs as loops and branches and provides for the writing of functions and procedures.
These capabilities are discussed in this section.
The first step in programming is to provide script files, in which MATLAB command sequences are collected into simple procedures.
This involves writing the MATLAB command sequences with a text editorthat can be opened, e.g., with the menu entry File - new - m-file in the MATLAB workspace (see Section 1.7), into a file and then saving this file under a name (e.g., proceed.m) or as a so-called m- file in a path accessible to MATLAB. (It might be a good idea to check the execution of the path command in Section 1.2.6 again.)
The sequence of commands can then be executed in the command window with the command proced. In order to avoid problems, whenever possible you must not use any previously employed command name. You can check whether such a command name already exists by, for example, just typing help