How do I create a tabbed GUI in MatLab?

后端 未结 2 1382
傲寒
傲寒 2021-02-09 06:07

I want to create a tabbed GUI in which first tab is for reading input, then the input is displayed on the GUI. The User should be able to select the data from GUI and then give

相关标签:
2条回答
  • 2021-02-09 06:40

    You can also create tabs from a GUIDE created GUI with the help of a utility available from Matlab File Exchange that I wrote.

    The usage is fairly simple:

    1. Create a pane with tag set to Tab? where ? is any letter or number (e.g. TabA). This main pane should be left empty and determines the size and location of the tab group (uitabgroup).
    2. Create additional panes with a tag name that starts with the name of the main pane. All other controls should be added to these panes.
    3. In the Guide generated function xxx_OpeningFcn add the following:

      handles.tabManager = TabManager( hObject );

    The location of the additional panes is not important but it is generally easier to edit the GUI if they are in the same location as the main pane. You can edit the panes even if they are overlaid by cycling through the panes with the "Send to back" command from the Guide pop up menu.

    0 讨论(0)
  • 2021-02-09 07:00

    Here is a simple example using the semi-documented function UITAB to create tabs:

    function tabbedGUI()
        %# create tabbed GUI
        hFig = figure('Menubar','none');
        s = warning('off', 'MATLAB:uitabgroup:OldVersion');
        hTabGroup = uitabgroup('Parent',hFig);
        warning(s);
        hTabs(1) = uitab('Parent',hTabGroup, 'Title','Data');
        hTabs(2) = uitab('Parent',hTabGroup, 'Title','Params');
        hTabs(3) = uitab('Parent',hTabGroup, 'Title','Plot');
        set(hTabGroup, 'SelectedTab',hTabs(1));
    
        %# populate tabs with UI components
        uicontrol('Style','pushbutton', 'String','Load data...', ...
            'Parent',hTabs(1), 'Callback',@loadButtonCallback);
        uicontrol('Style','popupmenu', 'String','r|g|b', ...
            'Parent',hTabs(2), 'Callback',@popupCallback);
        hAx = axes('Parent',hTabs(3));
        hLine = plot(NaN, NaN, 'Parent',hAx, 'Color','r');
    
        %# button callback
        function loadButtonCallback(src,evt)
            %# load data
            [fName,pName] = uigetfile('*.mat', 'Load data');
            if pName == 0, return; end
            data = load(fullfile(pName,fName), '-mat', 'X');
    
            %# plot
            set(hLine, 'XData',data.X(:,1), 'YData',data.X(:,2));
    
            %# swithc to plot tab
            set(hTabGroup, 'SelectedTab',hTabs(3));
            drawnow
        end
    
        %# drop-down menu callback
        function popupCallback(src,evt)
            %# update plot color
            val = get(src,'Value');
            clr = {'r' 'g' 'b'};
            set(hLine, 'Color',clr{val})
    
            %# swithc to plot tab
            set(hTabGroup, 'SelectedTab',hTabs(3));
            drawnow
        end
    end
    

    tab1 tab2 tab3

    0 讨论(0)
提交回复
热议问题