如何通过功能单选按钮,在MATLAB使用指南创建一个按钮组中? [英] How to pass function to radio button in a button group created using guide in MATLAB?
问题描述
我创建四个单选按钮和使用指南一个按钮一个按钮组。
有四个功能,一个用于分别写入每个单选按钮。
- 如何从各自的单选按钮调用这些功能。
- 当一个按钮为pressed,与活动单选按钮应该执行相关的功能。
:一种为按钮组回调的解决方案:SelectionChangeFCN
使用的选择更改的回调属性(右键点击按钮组,选择的查看Callbacks-> SelectionChangeFcn 的)的 uipanel 。在 EVENTDATA 的参数包含手柄pviously选择单选按钮当前和$ P $。在 EVENTDATA 的参数是具有以下字段的结构:
- 事件名称
- 的OldValue
- 的NewValue
因此,根据 eventdata.NewValue 的值;例如:
函数uipanel1_SelectionChangeFcn(hObject,EVENTDATA,把手)
...
newButton = GET(eventdata.NewValue,'标签');
切换newButton
案radiobutton1
%code为1单选框这里
案radiobutton2
%code为单选2在这里
...
结束
...
一种按钮回调的解决方案
回调您的按钮的可能沿东西线
函数button1_Callback(hObject,EVENTDATA,把手)
h_selectedRadioButton = GET(handles.uipanel1,'SelectedObject');
selectedRadioTag = GET(h_selectedRadioButton,'标签')
切换selectedRadioTag
案radiobutton1 案radiobutton2
...
结束
我也请您看看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.
- How do you to call these functions from respective radio buttons.
- When a push button is pressed, the function associated with the active radio button should execute.
A solution for the Button Group Callback: SelectionChangeFCN
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:
- EventName
- OldValue
- 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
...
A solution for the push button callback
The callback for your push button could have something along the lines of
function button1_Callback(hObject,eventdata,handles)
h_selectedRadioButton = get(handles.uipanel1,'SelectedObject');
selectedRadioTag = get(h_selectedRadioButton,'tag')
switch selectedRadioTag
case 'radiobutton1'
case 'radiobutton2'
...
end
I also refer you to the MATLAB documentation for more information on Handle Graphics and building graphical user interfaces.
这篇关于如何通过功能单选按钮,在MATLAB使用指南创建一个按钮组中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!