How do I pass value of State Button in app designer into a Simulink model?

3 次查看(过去 30 天)
I have created and linked a simple app using app designer that has just one State Button and a basic simulink model that has a switch block. I'd like to use the value of the state button (0 or 1) as the second input to the switch block, so the logic through the switch block changes when the state button is pressed/released. How do I do this? Usually connections are made using bindings, but for a state button app designer states 'bindings not supported'. I'm thinking there must be a way around this maybe using a callback - so that when the button is pressed the callback sets the value of a Variable in the model workspace that is picked up by an input into the switch state etc.. but I've had a go and can't see how to do this.
  2 个评论
Amish
Amish 2025-3-25
You can define a variable in the Model Workspace that is connected to the control input of the switch block. This variable can then be modified using a Callback function for the State button in the app using the assignin and set_param function to update the variable.
Neil Smithson
Neil Smithson 2025-4-4
Thank you. Yes the key bit I was missing is setting the variable up in the model worksapce. I then used setVariable to update the value:
app.Simulation.setVariable('myVariable', app.appName, 'Workspace', 'SimulinkModelName');
It's all working now.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Simulink Environment Customization 的更多信息

产品


版本

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by