使用radiobutton和滑块刷新指南

时间:2012-12-28 19:25:31

标签: matlab slider radio-button matlab-guide

我有一个问题,包括radiobuttons和滑块。我的目标是:当滑块的值改变时,必须重新运行当前所选的单选按钮中的代码以刷新效果。

滑块的最大值,最小值和步长在开启函数中定义,当前值定义为handles.value

这是我的滑码。

function slider1_Callback(hObject, eventdata, handles)
% hObject    handle to slider1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

handles.svalue = get(handles.slider1, 'Value');

guidata(hObject, handles)

这是我的radiobutton组选择更改代码。

function uipanel3_SelectionChangeFcn(hObject, eventdata, handles)
% hObject    handle to the selected object in uipanel3 
% 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)
switch get(eventdata.NewValue,'Tag') % Get Tag of selected object.
    case 'hte'
        h_te = zeros(handles.rows, handles.colums);

        for m = handles.row_0:handles.rows
            gauss = fspecial('gaussian',[1 round(1+handles.svalue*(m-handles.row_0+1))], (0.3*round(1+handles.svalue*(m-handles.row_0+1))));
            h_te(m,:,1) = filter2(gauss, handles.img_d(m,:,1));
            h_te(m,:,2) = filter2(gauss, handles.img_d(m,:,2));
            h_te(m,:,3) = filter2(gauss, handles.img_d(m,:,3));
            h_te(handles.rows-m+1,:,1) = filter2(gauss, handles.img_d(handles.rows-m+1,:,1));
            h_te(handles.rows-m+1,:,2) = filter2(gauss, handles.img_d(handles.rows-m+1,:,2));
            h_te(handles.rows-m+1,:,3) = filter2(gauss, handles.img_d(handles.rows-m+1,:,3));
        end

        axes(handles.axes2);
        imshow(h_te);

    case 'hc'
        h_c = zeros(handles.rows, handles.colums);

        for m = handles.row_0:handles.rows
            gauss = fspecial('gaussian',[1 round(1+handles.svalue*(m-handles.row_0+1))], (0.3*round(1+handles.svalue*(m-handles.row_0+1))));
            h_c(m-handles.row_0+1,:,1) = filter2(gauss, handles.img_d(m-handles.row_0+1,:,1));
            h_c(m-handles.row_0+1,:,2) = filter2(gauss, handles.img_d(m-handles.row_0+1,:,2));
            h_c(m-handles.row_0+1,:,3) = filter2(gauss, handles.img_d(m-handles.row_0+1,:,3));
            h_c(handles.rows-m+handles.row_0,:,1) = filter2(gauss, handles.img_d(handles.rows-m+handles.row_0,:,1));
            h_c(handles.rows-m+handles.row_0,:,2) = filter2(gauss, handles.img_d(handles.rows-m+handles.row_0,:,2));
            h_c(handles.rows-m+handles.row_0,:,3) = filter2(gauss, handles.img_d(handles.rows-m+handles.row_0,:,3));
        end

        axes(handles.axes2);
        imshow(h_c);

    case 'vlr'
        v_lr = zeros(handles.rows, handles.colums);

        for m = handles.colum_0:handles.colums
            gauss = fspecial('gaussian',[round(1+handles.svalue*(m-handles.colum_0+1)) 1], (0.3*round(1+handles.svalue*(m-handles.colum_0+1))));
            v_lr(:,m,1) = filter2(gauss, handles.img_d(:,m,1));
            v_lr(:,m,2) = filter2(gauss, handles.img_d(:,m,2));
            v_lr(:,m,3) = filter2(gauss, handles.img_d(:,m,3));
            v_lr(:,handles.colums-m+1,1) = filter2(gauss, handles.img_d(:,handles.colums-m+1,1));
            v_lr(:,handles.colums-m+1,2) = filter2(gauss, handles.img_d(:,handles.colums-m+1,2));
            v_lr(:,handles.colums-m+1,3) = filter2(gauss, handles.img_d(:,handles.colums-m+1,3));
        end

        axes(handles.axes2);
        imshow(v_lr);

    case 'vc'
        v_c = zeros(handles.rows, handles.colums);

        for m = handles.colum_0:handles.colums
            gauss = fspecial('gaussian',[round(1+handles.svalue*(m-handles.colum_0+1)) 1], (0.3*round(1+handles.svalue*(m-handles.colum_0+1))));
            v_c(:,m-handles.colum_0+1,1) = filter2(gauss, handles.img_d(:,m-handles.colum_0+1,1));
            v_c(:,m-handles.colum_0+1,2) = filter2(gauss, handles.img_d(:,m-handles.colum_0+1,2));
            v_c(:,m-handles.colum_0+1,3) = filter2(gauss, handles.img_d(:,m-handles.colum_0+1,3));
            v_c(:,handles.colums-m+handles.colum_0,1) = filter2(gauss, handles.img_d(:,handles.colums-m+handles.colum_0,1));
            v_c(:,handles.colums-m+handles.colum_0,2) = filter2(gauss, handles.img_d(:,handles.colums-m+handles.colum_0,2));
            v_c(:,handles.colums-m+handles.colum_0,3) = filter2(gauss, handles.img_d(:,handles.colums-m+handles.colum_0,3));
        end

        axes(handles.axes2);
        imshow(v_c);

end
guidata(hObject, handles)

我认为在滑块内部调用uipanel3函数可以工作,但事实并非如此。这是我认为可行的。

function slider1_Callback(hObject, eventdata, handles)
% hObject    handle to slider1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

handles.svalue = get(handles.slider1, 'Value');

uipanel3_SelectionChangeFcn(hObject, eventdata, handles);

guidata(hObject, handles)

1 个答案:

答案 0 :(得分:1)

它不起作用,因为hObject和eventdata用于滑块,而不是buttongroup,因此eventdata不包含您要查找的字段。您可以手动生成带有必填字段的eventdata,虽然它有点像黑客,而Oldvalue实际上并不是它应该是...

尝试

eventdata_new.EventName = 'SelectionChanged';
eventdata_new.OldValue = get(handles.uipanel3,'SelectedObject');
eventdata_new.NewValue = get(handles.uipanel3,'SelectedObject');

uipanel3_SelectionChangeFcn(handles.uipanel3, eventdata_new, handles);

而不是

uipanel3_SelectionChangeFcn(hObject, eventdata, handles);