how to change default radiobutton ?
Ältere Kommentare anzeigen
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
Akzeptierte Antwort
Weitere Antworten (2)
Image Analyst
am 6 Mai 2016
0 Stimmen
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 Kommentare
ElizabethR
am 8 Mai 2016
Bearbeitet: ElizabethR
am 8 Mai 2016
Image Analyst
am 8 Mai 2016
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
am 8 Mai 2016
Bearbeitet: ElizabethR
am 8 Mai 2016
Image Analyst
am 8 Mai 2016
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
am 9 Mai 2016
Bearbeitet: ElizabethR
am 9 Mai 2016
Image Analyst
am 9 Mai 2016
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
am 10 Mai 2016
Bearbeitet: ElizabethR
am 10 Mai 2016
Image Analyst
am 10 Mai 2016
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
am 16 Jun. 2016
Stalin Samuel
am 6 Mai 2016
*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);
Kategorien
Mehr zu Interactive Control and Callbacks finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
