How to initiate an existing callback from a current callback in Matlab app-designer?
48 次查看(过去 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
0 个评论
采纳的回答
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 个评论
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 Center 和 File Exchange 中查找有关 Migrate GUIDE Apps 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!