【问题标题】:Get GUI data from MATLAB programmatically (without GUIDE)以编程方式从 MATLAB 获取 GUI 数据(无 GUIDE)
【发布时间】:2023-03-13 23:34:01
【问题描述】:

如果不使用 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

【问题讨论】:

    标签: matlab matlab-figure matlab-guide uicontrol


    【解决方案1】:

    界面代码:

    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
    

    【讨论】:

    • 噢!我忽略的简单修复。感谢您的帮助,它完美运行!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-14
    • 1970-01-01
    相关资源
    最近更新 更多