6

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

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

如果用户关闭等待栏(单击窗口的),我想停止此脚本X,而无需添加取消按钮。

有什么办法吗?

4

2 回答 2

5

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

if ~ishandle(h)
    break
end
于 2013-01-23T17:19:25.223 回答
1

你可以尝试这样的事情:

if ishandle(h),
   close(h);
   % Your code here
else
    %waitbar has been closed by the user
    % call throw, return, or break
end

希望能帮助到你,

于 2013-01-23T17:23:47.667 回答