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

60 vues (au cours des 30 derniers jours)
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

Réponse acceptée

Cris LaPierre
Cris LaPierre le 9 Sep 2019
Modifié(e) : Cris LaPierre le 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 commentaires
Leon
Leon le 9 Sep 2019
Modifié(e) : Leon le 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 le 25 Oct 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();.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Develop Apps Using App Designer dans Help Center et File Exchange

Produits


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by