Main Content

万博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).

  1. Install and configure the development version ofMATLAB Web App Server™.

  2. Copy the Simulink model fileMassSpringDamperModel.slxand the corresponding MATLAB appMassSpringDamperApp.mlappto 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
  3. Open theMassSpringDamperApp.mlappin MATLAB App Designer and switch toCode View. Verify that theSimulink CompilerAPIs to create a simulation are present in theSimulateButtonPushedcallback.

Package and Create Web App

  1. Start MATLAB.

  2. TypewebAppCompilerat the MATLAB command line to open theWeb App Compiler应用程序。

  3. In theMAIN FILEsection of the toolstrip, click thebutton to add theMassSpringDamperApp.mlappfile 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.

  4. In theArchive informationsection, specify the archive name asmySimulinkSimulationWebApp.

  5. ClickPackageto package the app, and create a web app archive (.ctffile).

    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.

  6. 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 exactmccsyntax used to package and create the web app archive.

Deploy Web App

  1. Navigate to the project folder generated by Web App Compiler during the packaging process.

  2. Copy the web app archive filemySimulinkSimulationWebApp.ctfto 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.

  3. 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

  1. To run a web app, click themySimulinkSimulationWebApptile on the web apps home page.

    The web app opens in a new tab.

  2. Click theSimulatebutton to run the simulation.

    You have successfully created, deployed, and run a web app.

Related Topics