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

조회 수: 63 (최근 30일)
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

채택된 답변

Cris LaPierre
Cris LaPierre 2019년 9월 9일
편집: Cris LaPierre 2021년 11월 10일
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
Leon
Leon 2019년 9월 9일
편집: Leon 2019년 9월 9일
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 2019년 10월 25일
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();.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Develop Apps Using App Designer에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by