Code covered by the BSD License  

Highlights from
center window

from center window by Stiphu
put a GUI into the middle of the screen

centerWindow(hWindow)
function centerWindow(hWindow)
% centerWindow(hWindow): Put the window with the handle 'hWindow' into the
%   middle of the screen
%   
% Examples   
%   hWindow = figure; 
%   centerWindow(hWindow)
%
% =========================================================================
% centerWindow
% =========================================================================
% 
% Author:   Stephan Schmutz
% E-Mail:   stiphu@gmail.com
% Company:  University of Bern
% Date:     01.09.2010
% Version:  V 1.0
% -------------------------------------------------------------------------

% Check input arguments
if nargin ~= 1
    error('MATLAB:centerWindow:InvalidArguments','check input arguments');
elseif ~ishandle(hWindow) || ~strcmp(get(hWindow,'Type'),'figure')
    error('MATLAB:centerWindow:InvalidInputs','input argument is not valid figure handle');
end

% Save original units and put units to pixels
origUnits = get(hWindow,'Units');
set(hWindow,'Units','Pixels')
% Get the figure position
figPos = get(hWindow,'Position');
% Get the screen size
screenSize = get(0,'ScreenSize');
% Calculate new position
figPos(1) = (screenSize(3)-figPos(3))/2;
figPos(2) = (screenSize(4)-figPos(4))/2;
% Set new figure position
set(hWindow,'Position',figPos)
% Set units to original
set(hWindow,'Units',origUnits)

Contact us at files@mathworks.com