MATLAB: Size buttongroup height gui

buttongroupheighsize;

Hi, I need resize my buttongroup in which are 6 checkboxes. If number in edit box is lower than 3, buttongroup should be smaller than if the nimber in edit box is higher than 3. I can it resize, but it is not exactly what I need
My code is:
handles.hodnota=str2double(get(handles.edit1,'String'));
if handles.hodnota>2
set(handles.uibuttongroup1,'Position',[29.8 2.23 20.2 15])
else
set(handles.uibuttongroup1,'Position',[29.8 2.23 20.2 6])
end

Best Answer

When you change the Position of the uibuttongroup, you do not automatically also change the Position of any of the uicontrol style radio or push that are parented to the uibuttongroup -- not unless those uicontrol were set to 'units', 'normalized' (and if they were set to that, then they would all crowd together in the reduced size uibuttongroup.)
Position for a uicontrol starts from the bottom left corner of its container. You are putting your highest numbered buttons, 5 and 6, at the bottom of the display, where they have the smaller coordinates than your buttons like 1 and 2 have. When you then make the uibuttongroup smaller, the uicontrol that are going to remain visible within the uibuttongroup are the uicontrol with the smaller coordinates -- the bottom ones, not the top ones.
Therefore, if you want to use a smaller uibuttongroup because fewer buttons are needed, then you will need to change the Position of each of the uicontrol so that the ones you want are visible inside the container. Set the other uicontrol to visible off.
... Or, just dynamically create the buttons according to how many you need, instead of statically creating them and then having to fight the positioning routines.