以编程方式从MATLAB获取GUI数据(无GUIDE)

时间:2016-10-12 05:53:21

标签: matlab matlab-figure matlab-guide uicontrol

不使用GUIDE按下按钮后如何获取编辑uicontrol的值?

示例:

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

1 个答案:

答案 0 :(得分: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