Pressing a button in MATLAB app designer which changes a value of a variable in stateflow

23 次查看(过去 30 天)
Hello, so I am trying to press a button and when the callback for the button pushed is called, the program should change the value of a variable in the stateflow diagram. In order to do this, I have done the following:
In the startup function I have used the following line of code which links the stateflow chart to the app designer:
function startupFcn(app)
app.compLogic = mylogic('app', app);
end
Then in the callback for the button:
function ButtonPushed(app, event)
app.keyrequest = 1;
end
The variable keyrequest is a variable in the stateflow diagram, and by setting the value of this variable to something other than 0, the state machine starts to operate. I have tried to add the keyrequest as a property, but it still wasn't working. I feel like I need to use compLogic thing, but I don't really know how.
Any help would be much appreciated.
Thank you in advance!

回答(1 个)

Pavan Guntha
Pavan Guntha 2021-8-19
Hello Tb,
I understand that the issue here is with changing the data within stateflow by an action made through app (like button clicks). You could make use of events in stateflow which can easily be integrated with the components in app designer through callbacks. You could have a look at the attached files to understand a simple example which illustrates how we can control a state transfer through a button click. For more details, you could have a look at the example illustrated in the following page:
Hope this helps!

类别

Help CenterFile Exchange 中查找有关 Complex Logic 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by