Local Variables in Procedures
MuPAD® notebooks will be removed in a future release. Use MATLAB® live scripts instead.
MATLAB live scripts support most MuPAD functionality, though there are some differences. For more information, see Convert MuPAD Notebooks to MATLAB Live Scripts.
Local variables (variables in the programming sense, with “lexical
scoping”) are of domain type
When writing MuPAD® functions, often intermediate results need to be stored and retrieved. Like most programming languages, MuPAD offers “local variables” for this purpose. These local variables do not conflict with global identifiers of the same name nor with other local variables of the same name used at other places.
Local variables use “lexical scoping”, i.e., they
can be used in all program code that is written inside the body of
the procedure declaring the local variable. Note that returning anything
with a reference to a local variable requires the use of
escape in the procedure definition.
Local variables can be assigned values and these values can later be retrieved.
Local variables are created by using either the special names
one of the names declared with the keyword
a procedure definition.