Hi, everyone.
My name is Rahul Kumar and I'm part of the Simulink
Development Team.
In this video, I'm going to show you
how you can automatically generate a MATLAB
app from Simulink model.
Generating an app allows you to share your model with users
that may not be familiar with Simulink
and it opens up access for your models.
This functionality has been available in the command line
since our 2020 B, and now you can access it directly
from the Simulink tool strip.
Here I have a model with Simulink
to the vehicle dynamics based on the road suspension
interaction.
I can create a MATLAB app for this model
and expose the parameters, such as vehicle mass or suspension
stiffness, and damping coefficients.
These parameters are defined as variables in the model.
For example, here are the stiffness
and damping coefficients.
These are defined in the road suspension interaction block.
Using the app, any user can see the impact
of changing those parameters on the record dynamics.
In order to create the app, I go into the Export option
under Save and choose simulation app.
This will bring up a dialog where you can choose a template
to create the app from and provide a name for the app.
We are going to use the built in multi pane
snap template for this demo.
Click on Create to create the app.
This will compile the model, identify the parameters
and outputs that can be plotted, and give you
an generated MATLAB app file.
Let's wait for this process to complete.
Once the app is generated, it is automatically launched.
And if you go to the folder location,
you will see an mlapp file right there.
In the app, you will see a screenshot
of the model, the variables that were used in the model,
along with the default values appear in this table here.
Let's just run with the default values for now.
And I'll click on the run button to start the simulations.
The model outputs the vehicle vertical displacement
in millimeters, which can be seen in this plot.
For this set of values, the maximum displacement
is about 8 millimeters.
Let's change the mass of the vehicle
and see the effect it has on the vertical displacement.
And now you can see that the results have changed slightly
and the maximum displacement for a heavier vehicle
is only about 6 millimeters.
In order to share this app with others
who may not have Simulink, we can now deploy this app.
So let me close out of this app here and open
the app in the App Designer.
In App Designer, you can click on the share dropdown button
and select the option to create a standalone application.
Here I will add a folder that is required for the app to run,
this assets folder.
And you click on the package to create
the standalone application.
When the packaging is complete, the folder
where the application was saved will open automatically
and you can go into the for testing folder
to test the application.
You can see the executable file here.
At this point, you can exit out of MATLAB.
You can run this application like any other Windows
application by double clicking it.
The application does require the MATLAB Compiler
Runtime, which you can download from the mathworks.com website.
I already have the Runtime installed,
so I can go ahead and run the application.
When the application launches, you can run the simulations
as we did before.
As I have shown you, it is extremely easy
to automatically generate an app for the model
and deploy it to share with other users.
So go ahead and try it out with your own models.
Thank you.