如何在MatLab中创建选项卡式GUI? [英] How do I create a tabbed GUI in MatLab?

查看:572
本文介绍了如何在MatLab中创建选项卡式GUI?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个选项卡式GUI,其中第一个选项卡用于读取输入,然后将输入显示在GUI上.用户应该能够从GUI中选择数据,然后将其作为算法的输入.用户还可以在另一个选项卡中选择算法的参数.在第三个选项卡中,用户可以看到结果图.

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 given as input to a algorithm. Also the user can select parameters for the algortihm in another tab. In the third tab, the user can see the resulting plots.

如何通过编程方式或使用GUIDE在MatLab中创建选项卡式GUI?

How do I create a tabbed GUI within MatLab either programmatically or using the GUIDE?

推荐答案

以下是使用半文档功能UITAB创建标签的简单示例:

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

这篇关于如何在MatLab中创建选项卡式GUI?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆