Generate, Modify and Deploy a MATLAB App for a Simulink Model
simulink.compiler.genapp enables you to automatically generate a
MATLAB® app for a Simulink® model. You can compile and deploy the automatically generated app using the
mcc command. This example generates an app for a model, compiles and
deploys the app, and shows how you can customize the app using the App Designer.
MultiSimPaneApp is the default template used for app generation.
With this template, the generated app works for and is customizable. This template also allows
you to pause a simulation, tune parameters in the middle of a simulation, and configure an app
This example shows you how to use the
simulink.compiler.genapp function to generate a deployable app for the
f14. You can use the generated app to tune the parameters of the model
and run simulations with different parameter values. You can also customize the app in the App
Designer and deploy the generated app for use outside of MATLAB.
Open the model
simulink.compiler.example.AppGeneration command loads the example
project on your path. This project contains all the files required for this example,
including the model. Open the model
Generate a MATLAB App for the Model
To generate the app, the
SaveFormat for the output data must be
Structure with time. To change
SaveFormat for the
f14 model, in the
Modelling tab of the Simulink Toolstrip, go to Model
Settings. In the Data Import/Export pane, change
You can generate a MATLAB app for the model from the Simulink toolstrip. On the Simulink
toolstrip, under Save, select Export Model to Simulation
App. Enter the app name as
f14app and browse to choose a
Alternatively, you can use the
simulink.compiler.genapp function to
generate an app for the
f14 model. Running the
simulink.compiler.genapp function with the model name as an argument
generates an app named
f14app, which is specified as an argument. The
default name of the generated app is
Compiler uses a default template to generate the app. You can tune the parameters and
simulate the model for which the app is generated. The generated app also provides a plot of
the simulation results. All these files are generated into the
simulink.compiler.genapp('f14', 'AppName', 'f14app');
After generating the app, Click to simulate the app.
On the right side of the model image, you can tune the parameter values and run simulations with different values.
Use the arrow at the bottom to display the plot for the simulation output. The Plot Layout controls allow you to add multiple plots. By default, there is one axis shown in this pane. You can always add/remove axes using Plot Layout controls
Use the arrows on the left side of the plots to open the Logged Signals pane. To display the signals in the plots, first select the plot and then check the signals in the signal pane. Repeat this process for all the plots. This functionality allows you to compare results and modify the app as needed.
Click Load on the toolstrip of the app to load parameters and input signals from external files. The setting Configure For Deployment configures the app so that it can be deployed and used independently from MATLAB. Deployment options are a standalone desktop app or a web app.
Once the app is generated, three folders are created in the app folder:
AppHelper — Contains almost all the code that is used by the generated app. You can use this folder to navigate through the app, to understand how the app works, and potentially customize it.
AppUtils — Contains scripts to help you deploy the app as a standalone desktop app or a web app, test the deployed standalone app in MATLAB, and run the generated app directly from MATLAB.