User`s guide
10 Examples of GUIDE GUIs
Change the Height
The height a nd width of the figure is specified in pix el units. Usin g units
of pixels enables maximizing and minimizing the figure to work properly.
Thecodeassumesthatitsdimensionsare470-by-250pixels. Iftheuser
attempts to change the height, the code restores the original height. However,
because the resize function is triggered w hen the user releases the mouse
button after changing the size, the resize function cannot always determine
the original position of the GUI on screen. Therefore, the resize function
applies a compensation to the vertical p osition (second element in the figure
Position vector) by adding the vertical p osition to the height when the mouse
is released and subtracting the original height.
When the figure is resized from the bottom, it stays in the same position.
When resized from the top, the figure moves to the location where the mouse
button is released.
Ensure the Resized Figure Is On Screen
The resize function c alls movegu i to ensure that the resized figure is on
screen regardless of where the user releases the m ouse.
The first time it runs, the GUI is displayed at the s ize and location specified
by the figure
Position property. You can set this property with the Property
Inspector when you create the GUI or change it in GUIDE at any time.
ResizeFcn Code Listing
function Resize Fcn( hObject, eventdata, handles, varargin)
% Handles resize behavior e xcept when docked. This is because a certain
% window height is always preserved, and b ecause docked windo ws can
% have arbitrary proportions.
%Figure Unit s are fixed as 'pixels'; uicontrol units are in 'characters'
Figure_Size = get(hObject,'Position');
% This is the figure's orig inal position in pi xel units
Original_Size = [350 700 470 250];
% If the figure seems to be maximized, do not resize at all
pix_pos = get(hObject,'Position ');
scr_size = get(0,'ScreenSize');
if .99*scr_s ize( 3) < pix_pos(3) % Apparentl y maximized
% When docked, get out
10-96