万博1manbetxSimulation Web App
This example shows how to create a web app containing a Simulink®simulation and host it on thedevelopment version of 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 theSimulink Compiler™product. In the workflow, you:
Package the MATLAB app containing Simulink simulation using the Web App Compiler app inMATLAB Compiler. This step creates a web app archive (
.ctf
) file.Deploy the web app archive (
.ctf
) file to thedevelopment version of MATLAB Web App Server.Run the web app from the web apps home page.
Prerequisites
Note
This example requires theSimulink Compilerproduct. For details, seeSimulink Compiler Workflow Overview(Simulink Compiler).
Install and configure the development version ofMATLAB Web App Server™.
For information on installing the server, seeInstall the Development Version of MATLAB Web App Server in MATLAB Compiler.
For information on configuring the server, seeConfigure the Development Version of MATLAB Web App Server in MATLAB Compiler.
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\R2022a\examples\simulinkcompiler\main\
Linux® /usr/local/MATLAB/R2022a/examples/simulinkcompiler/main
macOS /Applications/MATLAB/R2022a.app/examples/simulinkcompiler/main
Open the
MassSpringDamperApp.mlapp
in MATLAB App Designer and switch toCode View. Verify that theSimulink CompilerAPIs 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 theWeb App Compiler应用程序。In theMAIN FILEsection of the toolstrip, click the
button to add the
MassSpringDamperApp.mlapp
file to the project. The Web App Compiler automatically resizes to include an应用细节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 clickingEdit App Details. ClickRefreshto 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)添加一个描述你的我们b app in theSummaryfield. This description is visible on the web apps home page.
In theArchive informationsection, specify the archive name as
mySimulinkSimulationWebApp
.ClickPackageto package the app, and create a web app archive (
.ctf
file).In theSave Project对话框打开时,specify a project name and a location where you want to save the web app project.Web App Compilersaves your project and opens aPackagedialog box.
Once packaging is complete, in thePackagedialog box, clickOpen 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\R2022a\apps
Linux
/local/MathWorks/webapps/R2022a/apps
macOS
/Library/Application Support/MathWorks/webapps/R2022a/apps
You can also open the apps folder by clicking theOpen App Folderbutton in the server application. For more information, seeStart the Server Application.
Click theOpen Home Pagebutton in the server application.
This action opens the web apps home page using your default web browser. 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 theSimulatebutton to run the simulation.
You have successfully created, deployed, and run a web app.