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

2 visualizaciones (últimos 30 días)
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 comentarios
Amish
Amish el 25 de Mzo. de 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 el 4 de Abr. de 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.

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Simulink Environment Customization en Help Center y File Exchange.

Productos


Versión

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by