困难的部分是你的第一个问题。
我的第一个想法(更好的是下面)是建议您根据时间检查用户是否点击 OK 或超时:
tic
hmsg=msgbox('message','title','modal');
uiwait(hmsg,5); %wait 5 sec
然后根据时间检查用户是否点击按钮或执行是否由于超时而继续:
if toc < 5 %then the user hit the button before timeout
%no need to close the msgbox (user already did that)
%appropriate code here...
else %we got here due to timeout
close(hmsg); %close the msgbox
%appropriate code here
end;
如果他们在网络上遇到超时并且它试图关闭已经关闭的窗口,那么您可能会收到错误的小风险。如果这成为一个问题,我认为您可以测试句柄是否有效:
ishandle(hmsg)
在尝试关闭之前。
这是我认为更好的方法:
hmsg=msgbox('message','title','modal');
uiwait(hmsg,5); %wait 5 sec
%now check to see if hmsg is still a handle to find out what happened
if ishandle(hmsg) %then the window is still open (i.e. timeout)
disp('timeout');
close(hmsg);
%appropriate code here...
else %then they closed the window
disp('user hit button');
%other code here
end;