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 DOM_VAR.

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 option escape in the procedure definition.


Local variables can be assigned values and these values can later be retrieved.

Element Creation

Local variables are created by using either the special names dom or procname or one of the names declared with the keyword local inside a procedure definition.

See Also

MuPAD Domains

MuPAD Functions