单选按钮组 matlab

发布于 2024-09-01 06:26:39 字数 188 浏览 3 评论 0原文

我有两组按钮组。 第一组按钮有两个单选按钮,第二组有四个单选按钮。 如果在组 1 和组 2 中选择按钮 1。类似地,对于组 1 中的按钮 2 和组 2 中的任何一个,必须在单击按钮时使用这些组合进行相应的函数调用。怎么做。对于它们各自的组合,将有 8 个单独的函数调用。如何进行按钮组的组合。 switch case 或 if else 语句不起作用?请帮忙。

i have two set of button groups.
first button groups has two radio buttons and second group has four radio buttons.
if button 1 is selected in group1 and any one from the group 2. similarly for button2 in group 1 and any one from group2, respective function calls must be made on click of push button with these combinations. how to do it. there will be 8 separate function calls for their respective combinations. how to do the combination of button groups. switch case or if else statement did not work out?? kindly help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

清风疏影 2024-09-08 06:26:39

这是一个想法。

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

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

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

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

fcn_array{fcn_index1,fcn_index2}(arguments)

Here is an idea.

First you create 2x4 cell array of your functions.

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

Then do switch case for each radio button in a group and return an index (say fcn_index1 for 1st group, and fcn_index2 for the 2nd group), which button selected.

Then you can call a function from your array with those indexes:

fcn_array{fcn_index1,fcn_index2}(arguments)
≈。彩虹 2024-09-08 06:26:39

Switch 和 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

Switch and if..else should certainly work out, but you need to nest them, i.e. there's no way to switch on a pair of values.

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
谁把谁当真 2024-09-08 06:26:39

不是最好的风格,但如果它们都使用相同的参数,那么您可以根据选择的按钮使用 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'))< 索引子项相结合/代码>
并记下哪个是哪个)

Not the greatest of style, but if they all use the same arguments then you could get away with dynamically building the call with the eval function based on which buttons were selected (using sprintf and the 'SelectedObject' field of the radio groups and a tag such as:eval(sprintf('func%s%s(args)',get(get(handles.group1,'SelectedObject'),'Tag'),get(get(handles.group2,'SelectedObject'),'Tag')))

(Could be combined with indexing the children using find(get(handles.group1,'Children')==get(handles.group2,'SelectedObject'))
and taking note of which is which)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文