This topic shows how to generate MATLAB® code for creating and simulating model predictive controllers designed in the MPC Designer app. Generated MATLAB scripts are useful when you want to programmatically reproduce designs that you obtained interactively.
To create a MATLAB script:
In the MPC Designer app, interactively design and tune your model predictive controller.
On the Tuning tab, in the Analysis section, click the Export Controller arrow .
Alternatively, on the MPC Designer tab, in the Result, click Export Controller.
If you opened MPC Designer from Simulink®, click the Update and Simulate arrow .
Under Export Controller or Update and
In the Generate MATLAB Script dialog box, select one or more simulation scenarios to include in the generated script.
Click Generate Script to create the MATLAB script for creating the current MPC controller and running the selected simulation scenarios. The generated script opens in the MATLAB Editor.
In addition to generating a script, the app exports the following to the MATLAB workspace:
A copy of the plant used to create the controller, that is the controller internal plant model
Copies of the plants used in any simulation scenarios that do not use the default internal plant model
The reference and disturbance signals specified for each simulation scenario