[英]How to call a callback function in a MATLAB gui from another gui?
我有兩個用GUIDE制作的GUI。 我正在嘗試從GUI2調用GUI1中的按鈕回調函數。 這是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!
這是我為類型為“ struct”的輸入參數獲取未定義函數“ add_note_Callback”的錯誤。 任何幫助將不勝感激。
可能的解決方案如下。
假設您的GUI 1定義如下:
filename
( .m
和.fig
文件的名稱)= master_gui
tag
屬性定義為“ figure1” handlevisibility
屬性設置on
callback
: plot_something_Callback
然后,例如,要從GUI 2中的pushbutton
調用GUI 1中定義的plot_something_Callback
因此,在GUI 2 pushbutton callback
您可以編寫以下代碼:
% Get the GUI 1 obj
g_m=findobj('tag','figure1')
% Get GUI handles
gd_m=guidata(g_m);
% Call GUI 1 callback from GUI 2 callback
% master_gui('plot_something_Callback',gd_m.plot_something,[],g_m)
master_gui('plot_something_Callback',gd_m.plot_something,[],gd_m)
注意,GUI 1應該是打開的。
修改代碼 GUI 1回調調用中的最后一個參數是gd_m
,這是GUI 1 handles
抱歉,該錯誤(我最初發布的代碼有效,因為GUI 1回調未使用GUI 1句柄)
希望這可以幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.