1、使用button group绘制不同的正弦曲线,结果如图。
2、步骤:
2.1、一个button group,3个radio button和一个axes控件拖入GUI页面。设置三个单选按钮的Tag分别为r1, r2 , r3 。
2.2、进行如下操作:进入uipanel1_SelectionChangeFcn函数
2.3、代码如下:
function uipanel1_SelectionChangeFcn(hObject, eventdata, handles)%选择出现了变化
% hObject handle to the selected object in uipanel1
% eventdata structure with the following fields (see UIBUTTONGROUP)
% EventName: string 'SelectionChanged' (read only)
% OldValue: handle of the previously selected object or empty if none was selected
%以前选择的对象的句柄,如果没有选择则为空
% NewValue: handle of the currently selected object当前选中对象的句柄
% handles structure with handles and user data (see GUIDATA)
x=0:0.01:2*pi;
current_Obj=get(eventdata.NewValue,'Tag');%获取 当前 被选中的radio button的Tag
switch current_Obj %判断哪一个radio button被选中
case 'r1'
axes(handles.axes1);%将界面中的坐标系置为要操作的对象
y=sin(x);
plot(x,y); %绘制
case 'r2'
axes(handles.axes1);
y=cos(x);
plot(x,y);
case 'r3'
axes(handles.axes1);
y=sin(x)+cos(x);
plot(x,y);
end