0
votes

Without using GUIDE how would I get the value of an edit uicontrol after pressing a pushbutton?

Example:

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

Then in my class

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

1 Answers

2
votes

GUI code:

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

Class definition:

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