在关闭等待栏时中止当前脚本

dyn*_*mic 6 matlab

我正在使用这样的等待栏:

h = waitbar(0,'Please wait...');
for i=1:100, % computation here %
   waitbar(i/100)
   % other operation here
end
close(h) 
Run Code Online (Sandbox Code Playgroud)

如果用户关闭等待栏(单击X窗口),我想停止此脚本,而不必添加"取消"按钮.

有什么办法吗?

Jon*_*nas 5

您可以测试是否h是有效句柄,否则退出循环.将以下内容插入循环:

if ~ishandle(h)
    break
end
Run Code Online (Sandbox Code Playgroud)