MATLAB: Are uicontrols not sized properly until I resize the figure

MATLAB

I created a function that contains the following commands:
function f = stacktest
f = figure;
h = [];
h(2) = uicontrol('pos', [120 20 60 20]);
h(3) = uicontrol('pos', [120 20 60 20]);
h(4) = uicontrol('pos', [120 20 60 20]);
set(h(2),...
'style','frame',...
'back', 'white', ...
'pos',[5 5 100 200]);
set(h(3),...
'style','edit',...
'back', 'red', ...
'string','edit',...
'pos',[10 10 80 30]);
set(h(4),...
'style','text',...
'back', 'green', ...
'string','text',...
'pos',[10 60 80 30]);
When I execute the function, the edit uicontrol is not visible, until I manually resize the figure. If I execute the commands line by line with the debugger, then the edit uicontrol is visible.

Best Answer

This bug has been fixed in Release 14 Service Pack 2 (R14SP2). For previous releases, please read below for any possible workarounds:
We have verified that there is a bug in MATLAB 7.0 (R14) in the way that objects are drawn if their Position is modified after they are created. To work around this issue, you may need to experiment with the order that you modify the objects in. For example, the following code will display the uicontrols properly:
function f = stacktest
f = figure;
h = [];
h(2) = uicontrol('pos', [120 20 60 20]);
h(3) = uicontrol('pos', [120 20 60 20]);
h(4) = uicontrol('pos', [120 20 60 20]);
set(h(3),...
'style','edit',...
'back', 'red', ...
'string','edit',...
'pos',[10 10 80 30]);
set(h(4),...
'style','text',...
'back', 'green', ...
'string','text',...
'pos',[10 60 80 30]);
set(h(2),...
'style','frame',...
'back', 'white', ...
'pos',[5 5 100 200]);
Here, the uicontrol becomes a frame after the other uicontrols have been modified and moved.