Programming Basics

Procedures, control flow, interactive input


MuPAD® notebooks will be removed in a future release. Use MATLAB® live scripts instead.

To convert a MuPAD notebook file to a MATLAB live script file, see convertMuPADNotebook. MATLAB live scripts support most MuPAD functionality, although there are some differences. For more information, see Convert MuPAD Notebooks to MATLAB Live Scripts.

MuPAD supports standard programming structures, such as if-then-else statements and for-, while-, and repeat-loops.

When you have a sequence of commands to perform repeatedly or that you want to save for future reference, store them in a program file. A MuPAD program file is a text file that contains any code snippet that you want to store separately from other computations. Saving a code snippet as a program file can be very helpful when you want to use the code in several notebooks. Typically, a program file contains a single procedure, but it also can contain one or more procedures or functions, assignments, statements, tests, or any other valid MuPAD code.

As a shortcut for simple procedures, create and use functions. Compared to procedures, functions require less complicated syntax. Like procedures, functions let you use the same code for different arguments as many times as you need.