How to call a callback function in a MATLAB gui from another gui?
13 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (2)
Adam
el 1 de Jul. de 2015
Editada: Adam
el 1 de Jul. de 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 comentarios
Ephesians289
el 2 de Nov. de 2016
Editada: Walter Roberson
el 2 de Nov. de 2016
GUI_MFILE('CALLBACK',hObject,eventData,handles,...)
calls the local function named CALLBACK in GUI_MFILE.M with the given input arguments.
1 comentario
Santhosh
el 1 de Mzo. de 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 [.
Ver también
Categorías
Más información sobre Migrate GUIDE Apps en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!