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

61 visualizaciones (últimos 30 días)
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

Respuesta aceptada

Cris LaPierre
Cris LaPierre el 9 de Sept. de 2019
Editada: Cris LaPierre el 10 de Nov. de 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 comentarios
Leon
Leon el 9 de Sept. de 2019
Editada: Leon el 9 de Sept. de 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 el 25 de Oct. de 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();.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Develop Apps Using App Designer en Help Center y File Exchange.

Productos


Versión

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by