2016-10-12 38 views
0

不使用GUIDE如何在按下按鈕後獲得編輯uicontrol的值?以編程方式從MATLAB獲取GUI數據(不含GUIDE)

實施例:

fig = figure; 
input = uicontrol(fig, 'Style', 'edit', 'Tag', 'input'); 
btn = uicontrol(fig, 'Style', 'pushbutton', 'Callback', @obj.test); 
在我的類

然後

methods 
    function testing(src, event, handles) 
     msgbox(get(handles.input, 'string')); 
    end 
end 

回答

2

GUI代碼:

function gui_test 
    fig = figure; 
    obj= testclass; 
    input = uicontrol(fig, 'Style', 'edit', 'Tag', 'input','Position',[10 70 100 20]); 
    btn = uicontrol(fig, 'Style', 'pushbutton', 'Callback', {@obj.testing,input}); 
end 

類定義:

classdef testclass 
    methods 
     function testing(obj,src, event, handles) 
      msgbox(get(handles, 'string')); 
     end 
    end 
end 
+0

Doh!簡單的修復我忽略了。感謝您的幫助,它完美的工作! – Nick

相關問題