how to change default radiobutton ?

조회 수: 40(최근 30일)
ElizabethR
ElizabethR 2016년 5월 6일
댓글: Douglas Anderson 2022년 2월 11일
i have two radio button like in this image.
but, if i load the gui, and i choose the option 1 ( bwareopen ) it doesn't work. I must choose option 2 ( opening ) first, and then i choose option two ( opening ) if I want to proceed with option 1. How to fix it ? How to change default radio button ?? thanks
  댓글 수: 2
ElizabethR
ElizabethR 2016년 5월 6일
function prepo_SelectionChangeFcn(hObject, eventdata, handles)
% hObject handle to the selected object in prepo
% 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 'prepo1'
global image;
r=imresize(image,[128 128]);
bw=im2bw(r);
c=imcomplement(bw);
ba=bwareaopen(c,100);
d=imcomplement(ba);
se=strel('disk',2);
open=imopen(d,se);
axes(handles.axes2);
imshow(open);
case 'prepo2'
global image;
r=imresize(image,[128 128]);
bw=im2bw(r);
se=strel('disk',2);
open=imopen(bw,se);
axes(handles.axes2);
imshow(open);
end

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2016년 6월 16일
uibuttongroup always have one of the buttons selected. It is not possible to put a uibuttongroup into a state of not having any of the buttons selected.
What you can do is add a third button to the group whose Visible property is set 'off', and set up the uibuttongroup so that the third (invisible) button is the one initially selected. Neither of the two visible buttons will be selected if you do this, so you would be able to select the first button and have it generate the callback immediately.
  댓글 수: 2
Douglas Anderson
Douglas Anderson 2022년 2월 11일
Brilliant Walter! Thank you!

댓글을 달려면 로그인하십시오.

추가 답변(2개)

Image Analyst
Image Analyst 2016년 5월 6일
I don't know exactly what "it doesn't work" means. Were you expecting the state of the radio button to toggle? Were you expecting to have a callback function run automatically?
To set the default button to be selected, set the "Value" property of the button, in GUIDE, to be 1. The others in that button group will be set to zero and that one will be the one that's selected when your GUI launches.
  댓글 수: 9
ElizabethR
ElizabethR 2016년 6월 16일
hi image analyst, i've tried it. i've set a breakpoint. Then i click on radiobutton1, then click to radiobutton2, but, it always goes in 'switch get(eventdata.NewValue,'Tag') ' like image that i attach
and it the radiobutton didn't work if i first click in radiobutton1 after i lunch the gui. How to fix it ? hope you will help me. Thank you

댓글을 달려면 로그인하십시오.


Stalin Samuel
Stalin Samuel 2016년 5월 6일
*Example code*
function my
handles.FigureH = figure;
handles.radio(1) = uicontrol('Style', 'radiobutton', ...
'Callback', @myRadio, ...
'Units', 'pixels', ...
'Position', [10, 10, 110, 22], ...
'String', 'Bwareaopen', ...
'Value', 1);
handles.radio(2) = uicontrol('Style', 'radiobutton', ...
'Callback', @myRadio, ...
'Units', 'pixels', ...
'Position', [10, 40, 80, 22], ...
'String', 'opening', ...
'Value', 0);
...
guidata(handles.FigureH, handles);
function myRadio(RadioH, EventData)
handles = guidata(RadioH);
otherRadio = handles.radio(handles.radio ~= RadioH);
set(otherRadio, 'Value', 0);
  댓글 수: 1
ElizabethR
ElizabethR 2016년 5월 8일
function prepo_SelectionChangeFcn(hObject, eventdata, handles)
% hObject handle to the selected object in prepo
% 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 'prepo1'
global image;
r=imresize(image,[128 128]);
bw=im2bw(r);
c=imcomplement(bw);
ba=bwareaopen(c,100);
d=imcomplement(ba);
se=strel('disk',2);
open=imopen(d,se);
axes(handles.axes2);
imshow(open);
case 'prepo2'
global image;
r=imresize(image,[128 128]);
bw=im2bw(r);
se=strel('disk',2);
open=imopen(bw,se);
axes(handles.axes2);
imshow(open);
end
this is my code, so where i write your example code ?

댓글을 달려면 로그인하십시오.

범주

Find more on Interactive Control and Callbacks in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by