使用Simulink编译器部署应用程序设计器仿真金宝app
此示例可引导您完成在应用程序设计器中创建模拟应用程序的工作流程,并使用金宝app®编译器™to deploy it. The example explains the code that is used to build the app.
To open the example, type the following in the MATLAB®命令窗口,或单击“视图MATLAB代码”按钮。
openexample('金宝appSimulinkCompiler/exployingAsimulationAppingSimulinkCompilereXample')
Deploying A Simulation App with Simulink Compiler
在此示例中,我们使用在应用程序设计器中准备的应用程序,并使用Simulink编译器部署它。金宝app
Open and Explore Model
In this example, we use the model of a mass springer damper system. The mass-spring-damper model consists of discrete mass nodes distributed throughout an object and interconnected via a network of springs and dampers. This model is well-suited for modelling object with complex material properties such as non-linearity and elasticity. In this example we use the mass spring damper system. The system is parametrized by mass (m), spring stiffness (k), damping (b) and the initial position (x0). The input to the system is the applied force.
要探索具有可调参数的不同值的不同值的模型,请创建以下模型工作区变量:
质量 - m。
弹簧刚度-K。
阻尼 - b。
Initial position - xo.
To create the model workspace variables, go to the造型tab and select模型工作区在里面Data Repositories在里面Designsection. Use theAdd MATLAB Variablesicon to add the above four variables. Add the appropriate initial values, for example, 3, 128, 2 and 0.5 respectively.
open_system('MassSpringDamperModel');
在应用程序设计器中创建应用程序
使用MATLAB应用程序设计器创建一个应用程序,以模拟具有不同参数值和输入信号的模型。要了解有关如何使用应用程序设计师创建应用程序的更多信息,请参见Create and Run a Simple App Using App Designer使用massspringdamperapp.mlapp
file to use the app.
MassSpringDamperapp
应用详细信息
应用程序的主要部分是模拟按钮回调函数。它具有以下明显部分:设置仿真input
目的,configure it for deployment, simulate, and plot the simulation results.
The functionality of the application to change and experiment with the tunable parameters is defined in the callback function模拟ButtonPushed
。此回调功能使您可以通过修改应用程序设计器中的值来更改,实验和分析不同的模拟。
模拟Buttonpushed回调功能代码
本节说明为创建应用程序的编写代码,MassSpringDamperapp
。The callback function模拟ButtonPushed
is called in the app designed in the App Designer. This callback function defines how the model is simulated. We use the金宝appSimulink.SimulationInput
对象将变量设置为模型并使用这些变量来更改值并分析模型。
创建金宝appSimulink.SimulationInput
Object in the模拟ButtonPushed
功能
在里面模拟ButtonPushed
功能,创建一个仿真input
目的,SimInp for the modelMassSpringDamperModel
。使用setModelParameters
method on the仿真input
object. In this example, we set theStopTime
model parameter for the simulation.
Set the Values of the Tunable Parameters and the Input Signal
要将输入信号设置为模型,请使用ExternalInput
属性金宝appSimulink.SimulationInput
目的,siminp
。使用setVariables
method to set the values of the four tunable parameters. Create the force input signal and set it as theExternalInput
在仿真输入对象中。
配置用于部署
Now that we have assigned all the values to the variables and set the input signal, the金宝appSimulink.SimulationInput
需要配置对象进行部署。使用SIMulink.compiler.configureForDeployment
function of Simulink Compiler. This function handles all the settings required for the script to be compatible for deployment by setting the simulation mode to rapid accelerator, and by setting the parameterRapidAcceleratorUpToDateCheck
to离开
。
模拟和绘制结果
使用configured Simulink.SimulationInput object to run the simulation with theSIM
命令。使用仿真绘制结果Simulink.SimulationOutput
目的,SIMOut
。
Test Out the Application in App Designer
在部署应用程序之前,请确保应用程序在应用程序设计器中运行。点击模拟应用程序上的按钮可以通过模拟不同值的模型来验证应用程序是否有效。
编译脚本进行部署
要编译应用程序,请使用MCC
命令,然后是脚本名称。
MCC -M MasspringDamperapp.mlapp
Running the Deployed Application
Install MATLAB Runtime and Package the Deployable
To run the deployed executable, you need an appropriate runtime environment. For more information, seeMATLAB运行时。
Ensure that the path environment variable is free of other instances of MATLAB Runtime from previous installs. If there are any, remove them.
To install MATLAB Runtime, follow the instructions on安装和配置MATLAB运行时。
Compile the deployable for the first time as follows:
Enter
部署
在MATLAB命令窗口中命令并选择申请编译器。在里面主文件section, add the file to be deployed,
massspringdamperapp.mlapp
在里面Packaging Options在工具条上的部分,选择Runtime included in package并输入
deployed_installer
在里面text box.Click包裹在里面包裹section of the toolstrip.
包装准备好后,请使用
deployed_installer
在里面for_redistribution
folder to install the proper runtime environment for running the deployed application.
Run the Deployed Application
你可以run the deployed script only on the platform that the deployed script was developed on.
It is recommended to run the deployed application from the Windows Command Prompt. Running the deployed application from the command prompt also enables the script to print errors when something is wrong in the deployed application. These errors can help troubleshoot the problem.
Note
Themassspringdamperapp.mlapp
containserrordlg
, 和errordlg
is not supported on Web Apps.
See Also
SIMulink.compiler.configureForDeployment
|MCC
|部署
|金宝appSimulink.SimulationInput