How to call a callback function in a MATLAB gui from another gui?

13 次查看(过去 30 天)
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.

回答(2 个)

Adam
Adam 2015-7-1
编辑:Adam 2015-7-1
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.

Ephesians289
Ephesians289 2016-11-2
编辑:Walter Roberson 2016-11-2
GUI_MFILE('CALLBACK',hObject,eventData,handles,...)
calls the local function named CALLBACK in GUI_MFILE.M with the given input arguments.
  1 个评论
Santhosh
Santhosh 2017-3-1
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 [.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Migrate GUIDE Apps 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by