deploy simulink simulation web app
this example shows how to create a web app containing a simulink® simulation and host it on the matlab® web app server™. the example uses the mass spring damper model in simulink and a matlab app that invokes the model as a basis for the web app. the apis for creating a simulation can be found in the simulink compiler™ product. in the workflow, you:
package the matlab app containing simulink simulation using the web app compiler app in matlab compiler. this step creates a web app archive (
.ctf
) file.deploy the web app archive (
.ctf
) file to the matlab web app server.run the web app from the web apps home page.
prerequisites
note
this example requires the simulink compiler product. for details, see (simulink compiler).
install the matlab web app server product and set up the server.
for more information on installing the product, see .
for more information on setting up the server, see .
copy the simulink model file
massspringdampermodel.slx
and the corresponding matlab appmassspringdamperapp.mlapp
to your current working directory. the default location for the files is:operating system default location for files windows® c:\program files\matlab\r2023a\examples\simulinkcompiler\main\
linux® /usr/local/matlab/r2023a/examples/simulinkcompiler/main
macos /applications/matlab/r2023a.app/examples/simulinkcompiler/main
open the
massspringdamperapp.mlapp
in matlab app designer and switch to code view. verify that the simulink compiler apis to create a simulation are present in thesimulatebuttonpushed
callback.
package and create web app
start matlab.
type
webappcompiler
at the matlab command line to open the web app compiler app.in the main file section of the toolstrip, click the button to add the
massspringdamperapp.mlapp
file to the project. the web app compiler automatically resizes to include an app details section that contains information about the app such as app name, author, summary, description, and version. you can edit information about the app in app designer by clicking edit app details. click refresh to update web app compiler with any changes you have made.(optional) make sure to use a display name that is easy to distinguish when your web app is deployed to the server.
(optional) provide a version number for tracking purposes. the version number is visible on the web apps home page.
(optional) add a description for your web app in the summary field. this description is visible on the web apps home page.
in the archive information section, specify the archive name as
mysimulinksimulationwebapp
.click package to package the app, and create a web app archive (
.ctf
file).in the save project dialog box that opens, specify a project name and a location where you want to save the web app project. web app compiler saves your project and opens a package dialog box.
once packaging is complete, in the package dialog box, click open output folder. this opens the project folder, which contains the following files:
mysimulinksimulationwebapp.ctf
mccexcludedfiles.log
packaginglog.html
requiredmcrproducts.txt
you can view the log file,
packaginglog.html
, to see the exactmcc
syntax used to package and create the web app archive.
deploy web app
navigate to the project folder generated by web app compiler during the packaging process.
copy the web app archive file
mysimulinksimulationwebapp.ctf
to the app folder configured by the server. the default location is:operating system apps folder location windows
%programdata%\mathworks\webapps\r2023a\apps
linux
/local/mathworks/webapps/r2023a/apps
macos
/library/application support/mathworks/webapps/r2023a/apps
you can also get the location of the apps folder by executing at the system command shell.
open a web browser and navigate to the web apps home page using the url obtained from executing the command. you see a tile displaying the simple mortgage calculator web app. your web app is now deployed.
run web app
to run a web app, click the
mysimulinksimulationwebapp
tile on the web apps home page.the web app opens in a new tab.
click the simulate button to run the simulation.
you have successfully created, deployed, and run a web app.