MATLAB: Is there two ways to write a code that gives you figure at opening

codeguiguideMATLAB

When i work in gui and go to editor i get this kind of code (for example):
function radiobutton2_Callback(hObject, eventdata, handles)
and bellow of it i add what i want to do if this object is selected.But this code works too (just example):
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.
The second code gives you figure at opening from editor too, but i don't know how.Any help?

Best Answer

I am not clear as to what you are asking, so this might turn out not to be relevant:
1) When you are at the MATLAB command window, or inside a program, and you execute any graphics command, including plot() or uibuttongroup(), then if there is no "current figure", a figure will automatically be created to contain the graphics object, just as if you had used figure() yourself (and axes() too if necessary.)
2) When you create a GUI using GUIDE, then part of what GUIDE does on your behalf is to create a figure to hold everything. GUIDE saves that figure as a .fig file (.fig files are really .mat files.) When you run the .m file for the GUI, then the code that GUIDE added at the beginning will openfig() the saved figure, re-creating the figure; if you had previously used GUIDE to put a uibuttongroup inside the figure, then the uibuttongroup would be restored.
There are not really two different ways to create figures: it is just that if you use GUIDE, GUIDE takes care of creating the figure for you.