How to initiate an existing callback from a current callback in Matlab app-designer?

58 Ansichten (letzte 30 Tage)
In the below example, what I'm trying to achieve is to call back the 2nd function from the first callback function. How do I do that?
First callback
function NextButtonPushed(app, event)
app.StationNo.Value = app.StationNo.Value + 1;
callback to the bleow function
end
2nd callback
function PlotstationButtonPushed(app, event)
% ---Station No ---
b = app.StationNo.Value; % get the station no
% --- load the file ---
File1 = ['stations/', app.FileName.Value];
load (File1); % values are stored as 'Sta'
...
...
end

Akzeptierte Antwort

Cris LaPierre
Cris LaPierre am 9 Sep. 2019
Bearbeitet: Cris LaPierre am 10 Nov. 2021
callbacks are just functions. Call them using app.<callback name>. Just set the inputs correctly.
function NextButtonPushed(app, event)
app.StationNo.Value = app.StationNo.Value + 1;
% callback to the bleow function
app.PlotstationButtonPushed(event)
end
  2 Kommentare
Leon
Leon am 9 Sep. 2019
Bearbeitet: Leon am 9 Sep. 2019
It works! Thank you so much.
The only change I need to make is to remove the contents inside the parenthesis and change it to
app.PlotstationButtonPushed
Hope Q
Hope Q am 25 Okt. 2019
I have a pesonal best practice of "don't call a callback from a callback". Instead, write a function that performs the task and call that function from both callbacks, as needed
I haven't run into issues in App Designer (yet - I'm just learning) but I've seen issues arise in GUIDE projects if a developer loses track of the handles structure and the hObject that invoked the callback.
In GUIDE the function called from either callback would pass and return the handles structure. The hObject was preserved in the original callback so that handles was updated with guidata at the end of the callback.
handles = PerformTask(handles);
guidata(hObject, handles);
In App Designer the function could be defined as a private method and called from either callback.
app.PerformTask();.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Develop Apps Using App Designer finden Sie in Help Center und File Exchange

Produkte


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by