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

3 Ansichten (letzte 30 Tage)
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 Kommentare
Amish
Amish am 25 Mär. 2025
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 am 4 Apr. 2025
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.

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Simulink Environment Customization finden Sie in Help Center und File Exchange

Produkte


Version

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by