how to change default radiobutton ?

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 件のコメント

CS Researcher
CS Researcher 2016 年 5 月 6 日
Can you share your .m code?
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 日

1 投票

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 件のコメント

ElizabethR
ElizabethR 2016 年 6 月 16 日
hi Walter Roberson.. oohh yes, you are right. well, i never thought about it that way. i've tried, and it working perfectly. thank you so much Walter Roberson, God Bless ^^
Douglas Anderson
Douglas Anderson 2022 年 2 月 11 日
Brilliant Walter! Thank you!

サインインしてコメントする。

その他の回答 (2 件)

Image Analyst
Image Analyst 2016 年 5 月 6 日

0 投票

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 年 5 月 8 日
編集済み: ElizabethR 2016 年 5 月 8 日
Thanks for answare. no, i mean is when i load this gui, the radiobutton is always select in first option ( bwareaopen ). So, how to make the both radiobutton is not selected ??
Image Analyst
Image Analyst 2016 年 5 月 8 日
I don't know why you'd want a situation where none of the radio buttons is selected. That's the situation where you use checkboxes. Or even "popups"
However it is possible if you don't put the radio buttons into a group box. Just put them into a regular panel or on the main GUI background. Then set the values to both to be false, either in GUIDE or in your OpeningFcn() function. Then in the callback function for each, you have to manually set the other radio button to false. This is the way it was until several years ago when they introduced the groupbox which did that automatically.
ElizabethR
ElizabethR 2016 年 5 月 8 日
編集済み: ElizabethR 2016 年 5 月 8 日
because, if i load the gui, the raidobutton is always selected in the first option. when i want to choose the option one, the function in radiobutton1 is don't work. The function in radiobutton1 is work when i choose radiobutton2 and then i choose radiobutton1. So, i want to make the both radiobutton is not selected. So, when i load gui, i can directly choose the radiobutton1. hope you understand with what i mean. I'am sorry for my bad english.
Image Analyst
Image Analyst 2016 年 5 月 8 日
The radiobutton1 callback won't be called automatically as the program starts just because it's the default one selected. If you want to run it when you load/launch the GUI, you need to call its callback function explicitly from the OpeningFcn() function. Is running it automatically upon launch what you want?
ElizabethR
ElizabethR 2016 年 5 月 9 日
編集済み: ElizabethR 2016 年 5 月 9 日
no, i want when i launched the GUI, and i choose option one, it already processing. So, how to make this ?
Image Analyst
Image Analyst 2016 年 5 月 9 日
I don't know what this means. The GUI launches, okay, fine - it's waiting there for your inputs and clicks. Now you "choose option one" - meaning you click radio button 1. But then you say "it's already processing". So, how did it start processing before you clicked on it? The only way I know for that to happen is if you put a call to the radio button's callback in the OpeningFcn() function of the main GUI.
ElizabethR
ElizabethR 2016 年 5 月 10 日
編集済み: ElizabethR 2016 年 5 月 10 日
thanks for answare it, what i mean is, i have 2 radiobutton in button group. If i load GUI, i input the image and then i choose one of two radiobutton. When i load GUI and i choose the radio1, the function in radion 1 is not working. So, if i want to choose radio 1, i must choose radio2 first and then choose radio1. So the function in radio1 will work. sorry for my bad english. Hope you will understand
Image Analyst
Image Analyst 2016 年 5 月 10 日
The same prepo_SelectionChangeFcn() gets executed no matter which one you click on. Set a breakpoint in it and then run your GUI. Then click on radio button 1 and see if it goes into the prepo_SelectionChangeFcn() function. Then again when you click on radioobutton2, and then again when you click on radiobutton1 again. When does it stop at the breakpoint? It should stop there all three times. If not, attach your m-file and fig-file so i can try it.
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 日

0 投票

*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 ?

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeInteractive Control and Callbacks についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by