如何将函数传递给使用 MATLAB 中的指南创建的按钮组中的单选按钮? [英] How to pass function to radio button in a button group created using guide in MATLAB?

查看:18
本文介绍了如何将函数传递给使用 MATLAB 中的指南创建的按钮组中的单选按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个按钮组,其中包含四个单选按钮和一个使用指南的按钮.

I have created a button group with four radio buttons and a push button using guide.

有四个功能,每个单选按钮一个单独编写.

There are four functions, one for each radio button written separately.

  1. 如何从各个单选按钮调用这些函数.
  2. 按下按钮时,应执行与活动单选按钮相关的功能.

推荐答案

按钮组回调的解决方案:SelectionChangeFCN

使用uipanelSelection Change回调属性(右击Button Group并选择View Callbacks->SelectionChangeFcn).eventdata 参数包含当前和先前选择的单选按钮的句柄.eventdata 参数是具有以下字段的结构:

Use the Selection Change callback property (right click on the Button Group and select View Callbacks->SelectionChangeFcn) of the uipanel. The eventdata argument contains the handles to the current and previously selected radiobutton. The eventdata argument is a structure with the following fields:

  • 事件名称
  • 旧值
  • 新价值

所以,取决于eventdata.NewValue的值;例如

So, depending on the value of eventdata.NewValue; for example

function uipanel1_SelectionChangeFcn(hObject,eventdata,handles)
...
newButton=get(eventdata.NewValue,'tag');
switch newButton
     case 'radiobutton1'
         % code for radiobutton 1 here
     case 'radiobutton2'
         % code for radiobutton 2 here
     ...
end
...

按钮回调的解决方案

按钮的回调可能有一些类似

function button1_Callback(hObject,eventdata,handles)
h_selectedRadioButton = get(handles.uipanel1,'SelectedObject');
selectedRadioTag = get(h_selectedRadioButton,'tag')
switch selectedRadioTag
   case 'radiobutton1'

   case 'radiobutton2'
   ...
end

我还建议您参阅 MATLAB 文档以获取有关 的更多信息处理图形和构建图形用户界面.

I also refer you to the MATLAB documentation for more information on Handle Graphics and building graphical user interfaces.

这篇关于如何将函数传递给使用 MATLAB 中的指南创建的按钮组中的单选按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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