单选按钮组 matlab
我有两组按钮组。 第一组按钮有两个单选按钮,第二组有四个单选按钮。 如果在组 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是一个想法。
首先,创建函数的 2x4 元胞数组。
然后为组中的每个单选按钮执行
switch case
,并返回选择的按钮的索引(例如第一组为 fcn_index1,第二组为 fcn_index2)。然后您可以使用这些索引从数组中调用函数:
Here is an idea.
First you create 2x4 cell array of your functions.
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:
Switch 和 if..else 当然应该可行,但您需要嵌套它们,即无法打开一对值。
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.
不是最好的风格,但如果它们都使用相同的参数,那么您可以根据选择的按钮使用 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)