How can I pass parameters from App Designer to Simulink?
조회 수: 30 (최근 30일)
이전 댓글 표시
MathWorks Support Team
2020년 4월 25일
편집: MathWorks Support Team
2021년 9월 6일
In an app that runs a Simulink model, what is the best way to pass parameters from App Designer to Simulink?
채택된 답변
MathWorks Support Team
2021년 9월 2일
편집: MathWorks Support Team
2021년 9월 6일
The best way to change variables in a Simulink model from an App is to interface into the model using a Simulink.SimulationInput object.
The SimulationInput class contains several methods (setVariable, setExternalInput, etc) which are useful for modifying the variables and parameters of a Simulink Model prior to starting the simulation. For more information on the SimulationInput class, refer to its documentation page:
In this particular case, you can create and reference the SimulationInput object in the code of the App, pass in a handle to your Simulink model, and change variable values directly from the app. For example, inserting the following code into the App would allow you to set the value of a variable 'cost' inside a model named 'controllerModel'.
mdl = 'controllerModel'; % create a handle to the name of the Simulink model
in = Simulink.SimulationInput(mdl); % create a SimulationInput object for the model
in = in.setVariable('cost',50); % set the value of variable 'cost' to 50
The section titled "SimulateButtonPushed Callback Function Code" in the following example illustrates this workflow of modifying simulation data using the SimulationInput object.
Please note: the above example was written for an app deployed with Simulink Compiler. Simulink Compiler is NOT required to interface App Designer and Simulink, but the workflow demonstrated in the example is still applicable even without Simulink Compiler. For more information about deploying applications with Simulink Compiler, refer to the information in the documentation below.
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Simulink Environment Customization에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!