Programmatically event in App Designer, is it possible?
18 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Eric Delgado
am 20 Sep. 2022
Kommentiert: Adam Danz
am 21 Sep. 2022
I am trying to create an event programmatically in App Designer, like a "PushedButton" or a "ValueChanged". Is it possible? I know that I can call the callback function directly, without passing the "event" argument, but I wish I could use notify function.
notify(app.myButton, 'ButtonPushed')
% Error using matlab.ui.control.Button/notify
% Cannot notify listeners of event 'ButtonPushed' in class 'matlab.ui.control.Button'.
2 Kommentare
Akzeptierte Antwort
Adam Danz
am 21 Sep. 2022
Bearbeitet: Adam Danz
am 21 Sep. 2022
For push buttons, the event is a ButtonPushedData object with properties Source (button handle) and EventName ('ButtonPushed'). Your switch/case matches the Source with known button handles.
From what I understand, you want to directly call the ButtonsPushedCallback function and provide a known button handle so you can run some code that belongs to one of the cases. If that's correct, when you call ButtonsPushedCallback, if you have access to the app object, you can provide the button handle within a structure with a field named Source.
Example:
S = struct();
S.Source = app.Button1;
ButtonsPushedCallback(app, S)
2 Kommentare
Adam Danz
am 21 Sep. 2022
Glad it worked out! You could simplify my answer to create the structure and the field within the same line:
S = struct('Source', app.Button1);
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Creating, Deleting, and Querying Graphics Objects finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!