Is it possible to have a uiconfirm choose an option after a timeout period?
Show older comments
I am trying to modify my uiconfirm popup to select the 'DefaultOption' after some time to avoid having the popup open for a long period of time and holding up code execution.
I have already tried using a timer to select one of the options which didn't seem to work but maybe I did it wrong.
I can explain what I am trying to do and why in further detail if needed.
Here is a barebones example of what I am trying to modify:
closeHdlg = uiconfirm(MainFigure, "Title",'Program','Options',{'Retry','Disconnect','Continue'},'DefaultOption','Retry');
switch closeHdlg
case 'Retry'
% Hidden for confidentiality
case 'Disconnect'
% Hidden for confidentiality
case 'Continue'
% Hidden for confidentiality
case ''
% close box and do nothing
end % end switch
Accepted Answer
More Answers (1)
Jeff Mandel
on 25 Mar 2026
Simpler approach:
d = dialog('Position', [350 350 250 150], ...
'Name', 'Confirmation','UserData','Proceed');
uicontrol(d, 'Style', 'text', ...
'String', 'Dialog will timeout in 5 seconds', ...
'Position', [20 80 210 40]);
uicontrol(d, 'Style', 'pushbutton', ...
'String', 'Proceed', ...
'Position', [30 20 80 30], ...
'Callback', @buttonCallback);
uicontrol(d, 'Style', 'pushbutton', ...
'String', 'Cancel', ...
'Position', [140 20 80 30], ...
'Callback', @buttonCallback);
% Block execution for 5 seconds or until uiresume is called
uiwait(d,5);
fprintf("%s\n",d.UserData);
close(d);
function buttonCallback(object,~)
object.Parent.UserData = object.String;
uiresume(object.Parent);
end
Categories
Find more on Startup and Shutdown in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!