File: ef230-2023-08/www/examples/center_menu.m Download
%| Purpose: Create a centered MATLAB menu
%| Method: Create a timer that moves the menu after it is displayed
%|         because MATLAB doesn't provide a way of positioning the menu.
%|         This is kludgy, but it seems to work.
function r = center_menu(menutitle,varargin)
% Inputs: same as MATLAB's menu command
% Output: same as MATLAB's menu command

delay = 0.5; % seconds to wait before centering menu
% create a timer that will move the menu to the center after it is displayed
t = timer(  'StartDelay', delay, ...
            'TimerFcn', @(~,~)movegui('center') );
start(t); % start the timer
r = menu(menutitle,varargin); % display the menu (it will be moved after it displayed
delete(t); % delete the timer
end % centermenu