我正在使用这样的等候栏:
h = waitbar(0,'Please wait...');
for i=1:100, % computation here %
waitbar(i/100)
% other operation here
end
close(h)
如果用户关闭等待栏(点击窗口的X
),我想停止此脚本,而无需添加“取消”按钮。
有什么办法吗?
答案 0 :(得分:5)
您可以测试h
是否是有效句柄,否则退出循环。将以下内容插入循环:
if ~ishandle(h)
break
end
答案 1 :(得分:1)
您可以尝试这样的事情:
if ishandle(h),
close(h);
% Your code here
else
%waitbar has been closed by the user
% call throw, return, or break
end
希望它有所帮助,