MATLAB: Error using matlab.ui.Figure/set when calling menu function

MATLABmenu function errorscreensize error

When I try to use the function menu as the example 1 shows in the help document, it returns the following error:
Error using matlab.ui.Figure/set
While setting the 'Position' property of Figure: Width and height must be > 0
Error in menu>local_GUImenu (line 231)
set( menuFig, 'Position', [winLeftGap bottom winWide winHigh] );
Error in menu (line 43)
k = local_GUImenu( xHeader, ArgsIn );
I find that the variable "winHigh" is less than 0, which is caused by the negative value of "numRows" in the same function. While the negative numRows comes from the meaningless screensize
screensize = get(0,'ScreenSize'); % The return value is [0 0 1 1]
The platform information are show as followings:
windows 7 Professional K
service pack 1
64bit
Intel(R) core(TM) i7-3770 CPU
dual monitor (24inch,27inch) with same resolution: 1920x1080
Thanks! Looking forward to your reply!

Best Answer

Obviously the 'Units' of the root object have been set to 'normalized', while the function expect it as 'pixels'. Search in you code, e.g. startup.m if the units are modified from the default 'pixels' and remove the command. Alterntively modify the failing code:
bakUnits = get(0, 'Units');
set(0, 'Units', 'pixels');
screensize = get(0,'ScreenSize');
set(0, 'Units', bakUnits);
If you are working with modern Matlab systems, use groot instead of 0.