MATLAB: Uicontrols do not resize with figure window in the app

MATLABnormalizedpixelsrescaleresizeuicontroluifigureunits

I have an app with a pushbutton contained in a uipanel. When I run the app then resize the figure window, the panels do not change size. How do I get my panels to auto-scale as expected?
The reason I am resizing the window is because I have users with different screen sizes and screen resolutions. Thus, the app appears too large on some machines and too small on others, and thus needs to be resized.

Best Answer

A UIPanel or TabGroup will only resize if the components within that panel or tab group resize and thus force the panel or tab group to expand. For example, if you place an Axes inside a UIPanel, the axes will re-scale as the figure window is expanded, so the panel will expand too. However, if you place only a pushbutton inside the panel, no resizing will occur, since uicontrols do not automatically resize. Thus, the real issue here is that your uicontrols are not resizing.
To make your panels with uicontrols scale better, try the following:
1) Change the position "units" of each uicontrol to "normalized". For example,
f = uifigure;
pb = uicontrol('Style','pushbutton','String','Push Me');
pb.Units = "normalized";
A pushbutton will now scale properly when shrinking/expanding the figure window.
2) Simply make the figure larger in the Design View of App Designer by clicking and dragging on the lower right corner of the window canvas. Then resize the rest of the components appropriately (before running the app).
3) Make the figure appear the same relative size across computer screens with different resolution / dimensions. In a normal figures, this can be achieved with "normalized" units. However, a uifigure is currently limited to units of "pixels", which means that the figure window will have a different relative size on, say, a large 4k monitor than a small laptop. To imitate the behavior of "normalized" units, follow the method outlined in the MATLAB Answers post below:
If the figure window has the same relative size across different machines, there should be little need to resize the window in the first place.