有关matlab中groupbutton的

我希望点击一个pushbutton按钮,然后groupbutton内被选项才被执行,但现在是一选择其中的一个radiobutton就直接执行了,求解啊

第1个回答  2014-06-20

按下图所示,选择基本的按钮和坐标轴,另外选择一个Button group放在合适位置,然后分别添加四个单选按钮放在Button group里边。合理安排布局。

双击Button group按钮,将其title属性设置为算法选择。


双击每个单选按钮,将其String属性分别设置为 原图、sobel 、prewitt、canny


右键单击Button group选择View  callbacks,然后选中SelectionChangeFcn

即可进入代码书写区域

代码如下:

function suan_fa_xuan_ze_SelectionChangeFcn(hObject, eventdata, handles)

% hObject    handle to the selected object in suan_fa_xuan_ze 

% 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 

global im                                 %使用全局变量(已声明)

str=get(hObject,'string');       %拿到所选按钮的名称

axes(handles.axes2);            %在axes2坐标轴上显示处理后的图像

switch str

    case '原图'

        imshow(im);

    case 'sobel'    

        BW = edge(rgb2gray(im),'sobel');

         imshow(BW);

    case 'prewitt'   

        BW = edge(rgb2gray(im),'prewitt');

          imshow(BW);

    case 'canny'    

        BW = edge(rgb2gray(im),'canny');

            imshow(BW);

end

相似回答