How can I pass parameters from App Designer to Simulink?

45 ビュー (過去 30 日間)
MathWorks Support Team
MathWorks Support Team 2020 年 4 月 25 日
編集済み: MathWorks Support Team 2025 年 2 月 3 日
In an app that runs a Simulink model, what is the best way to pass parameters from App Designer to Simulink?

採用された回答

MathWorks Support Team
MathWorks Support Team 2025 年 1 月 17 日
編集済み: MathWorks Support Team 2025 年 2 月 3 日
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. To access the documentation for the SimulationInput class, execute the following command in the MATLAB R2020a command window:
>> web(fullfile(docroot, 'simulink/slref/simulink.simulationinput-class.html'))
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. To learn more about deploying applications with Simulink Compiler, execute the following command in the MATLAB R2020a command window:
>> web(fullfile(docroot, 'slcompiler/index.html'))
Please follow the below link to search for the required information regarding the current release:

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeModel Compatibility についてさらに検索

製品


リリース

R2018a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by