MATLAB: Placing radiobuttons with relative locations

MATLABuicontrol

How can I place buttons created by uicontrol() in a relative location, as opposed to absolute location, within a ui window?
It makes no sense to me that a uibuttongroup can be placed in a relative location, but the actual buttons can not. This is a problem when resizing a window.
For example, I can do:
button_group_1 = uibuttongroup('Visible','on','Position',[ 0.4 0 0.4 0.4 ]);
button_1 = uicontrol( button_group_1,'Style','radiobutton','String','button_1','Position',[ 10 50 100 50 ]);
But I can not do:
button_group_1 = uibuttongroup('Visible','on','Position',[ 0.4 0 0.4 0.4 ]);
button_1 = uicontrol( button_group_1,'Style','radiobutton','String','button_1','Position',[ 0.4 0 0.4 0.4 ]);
Could someone help me implement buttons in a relative position so that a window can be resized and their locations still make sense?

Best Answer

Hi Ryan1234321,
When creating GUIs by command without the use of GUIDE I do place all elements in absolute position. I take care that it fits well on my screen first. It is no problem to do so on any other machine, but GUI is going to be showed while all GUI elements are rescaled to a new window size.
My GUIs often contain a global variable "GUI" that is of type struct containing all figure handles where "GUI.fh" is the figure handle of the parent figure.
For changing the window size it is very effective to change the unit of fonts and general lengths into normalized:
function resize(~,~)
% Set all 'Units'-property within figure to 'normalized in order to
% allow for scaling
set(findall(GUI.fh,'Units','pixels'),'Units','normalized');
set(findall(GUI.fh,'FontUnits','points'),'FontUnits','normalized');
end
Thus, final lines in most GUIs are after building them the following:
drawnow();
resize();
set(GUI.fh,'ResizeFcn',@resize);
Kind regards,
Robert