How to call a callback function in a MATLAB gui from another gui?
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi All, I have two GUIs, made with GUIDE. I'm trying to call a pushbutton callback function in GUI1 from GUI2. Here is the code in GUI2
set(0,'showHiddenHandles','on');
hfig = gcf;
m_handles = guidata(hfig); % handles in GUI1
set(m_handles.show_status , 'String' , ...
[script sprintf('\n') s_response]); % this line works
set(m_handles.add_note , 'Enable' , 'off'); % this line also works
add_note_Callback(m_handles.add_note, eventdata, m_handles); % but this does not work!
Here is the error I get Undefined function 'add_note_Callback' for input arguments of type 'struct'. any help will be appreciated.
0 Kommentare
Antworten (2)
Adam
am 1 Jul. 2015
Bearbeitet: Adam
am 1 Jul. 2015
Factor out your callback function into its own file so you can call it and pass in the arguments.
You cannot see functions externally that are subfunctions of another function (such as a GUIDE GUI)
I would not recommend this method of programming in any way though. Having one GUI accessing the handles of another GUI is very dodgy design even though it is made possible by methods like showing hidden handles.
Unfortunately the alternative that I use is too complicated to explain in a manner for someone to understand who has never done Matlab OOP programming though so what I said first should work for you.
On a very high level though if you work with classes underlying your UIs you can pass these class objects from one UI to another (assuming they are handle-derived classes to pass by reference), attach listeners and then each GUI still controls all its own behaviour instead of GUIs dipping into each other and potentially creating all manner of hard to find bugs.
2 Kommentare
Ephesians289
am 2 Nov. 2016
Bearbeitet: Walter Roberson
am 2 Nov. 2016
GUI_MFILE('CALLBACK',hObject,eventData,handles,...)
calls the local function named CALLBACK in GUI_MFILE.M with the given input arguments.
1 Kommentar
Santhosh
am 1 Mär. 2017
how to use this command if i want to callback a pushbutton function from outside gui??? i am getting an error message showing
Error: Expression or statement is incorrect--possibly unbalanced (, {, or [.
Siehe auch
Kategorien
Mehr zu Migrate GUIDE Apps finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!