MATLAB: Can I force a radio button group to initialize with a certain button selected

matlab guiobject properties

As the question says, I want a particular button selected every time the radio button group is initialized. Can I "set()" this somehow?

Best Answer

Have a look at the selectedobject property.
h = uibuttongroup('Pos',[0 0 .2 1]);
u0 = uicontrol(h,'Style','Radio','String','Option 1',...
'pos',[10 350 100 30]);
u1 = uicontrol(h,'Style','Radio','String','Option 2',...
'pos',[10 250 100 30]);
u2 = uicontrol(h,'Style','Radio','String','Option 3',...
'pos',[10 150 100 30]);
set(h,'SelectedObject',u2); % Set the object.
.
.
.
If you are using GUIDE, simply put this code at the end of the GUI OpeningFcn. For example, if you GUI is called mygui, then look for mygui_OpeningFcn.
% Use the correct names, for the objects, of course...
set(handles.uipanel3,'selectedobject',handles.radiobutton3)