【发布时间】:2013-01-23 17:16:03
【问题描述】:
我正在使用这样的等待栏:
h = waitbar(0,'Please wait...');
for i=1:100, % computation here %
waitbar(i/100)
% other operation here
end
close(h)
如果用户关闭等待栏(单击窗口的X),我想停止此脚本,而无需添加取消按钮。
有什么办法吗?
【问题讨论】:
标签: matlab
我正在使用这样的等待栏:
h = waitbar(0,'Please wait...');
for i=1:100, % computation here %
waitbar(i/100)
% other operation here
end
close(h)
如果用户关闭等待栏(单击窗口的X),我想停止此脚本,而无需添加取消按钮。
有什么办法吗?
【问题讨论】:
标签: matlab
您可以测试h 是否为有效句柄,否则退出循环。在循环中插入以下内容:
if ~ishandle(h)
break
end
【讨论】:
你可以试试这样的:
if ishandle(h),
close(h);
% Your code here
else
%waitbar has been closed by the user
% call throw, return, or break
end
希望对你有帮助,
【讨论】:
return、break 或 throw 语句来跟进,具体取决于您使用它的位置
if ~ishandle(h)