单选按钮组matlab

时间:2010-05-09 18:51:35

标签: user-interface matlab radio-button

我有两组按钮组。 第一个按钮组有两个单选按钮,第二个按钮组有四个单选按钮。 如果在group1中选择了按钮1,而在组2中选择了任何一个,则类似于组1中的button2和group2中的任何一个,必须在单击具有这些组合的按钮时进行相应的函数调用。怎么做。它们各自的组合将有8个单独的函数调用。如何组合按钮组。切换案例或if else语句没有成功?请帮助。

3 个答案:

答案 0 :(得分:1)

这是一个想法。

首先,创建函数的2x4单元格数组。

fnc_array = {fcn11, fcn12, fcn13, fcn14; fcn21, fcn22, fcn23, fcn24};

然后对组中的每个单选按钮执行switch case并返回一个索引(例如第一组为fcn_index1,第二组为fcn_index2),选择该按钮。

然后,您可以使用这些索引从数组中调用函数:

fcn_array{fcn_index1,fcn_index2}(arguments)

答案 1 :(得分:0)

切换和if..else肯定会解决,但你需要嵌套它们,即无法打开一对值。

switch valA
    case 1
        if isB
            out = fcn11(args{:});
        else
            out = fcn12(args{:});
        end
    case 2
        if isB
            out = fcn21(args{:});
        else
            out = fcn22(args{:});
        end
    case 3
        if isB
            out = fcn31(args{:});
        else
            out = fcn32(args{:});
        end
    case 4
        if isB
            out = fcn41(args{:});
        else
            out = fcn42(args{:});
        end
end

答案 2 :(得分:0)

不是最好的样式,但如果它们都使用相同的参数,那么您可以根据选择的按钮使用eval函数动态构建调用(使用sprintf和无线电组的'SelectedObject'字段和一个标签,如:eval(sprintf('func%s%s(args)',get(get(handles.group1,'SelectedObject'),'Tag'),get(get(handles.group2,'SelectedObject'),'Tag'))

(可以与使用find(get(handles.group1,'Children')==get(handles.group2,'SelectedObject'))为孩子编制索引相结合 并注意哪个是哪个)

相关问题