I am using a waitbar like this:
h = waitbar(0,'Please wait...');
for i=1:100, % computation here %
waitbar(i/100)
% other operation here
end
close(h)
I would like to stop this script if the user close the waitbar (clicks the X
of the window), without having to add a Cancel button.
Is there any way to do it?
You can test whether h
is a valid handle, and exit the loop otherwise. Insert the following into your loop:
if ~ishandle(h)
break
end
You can try something like this :
if ishandle(h),
close(h);
% Your code here
else
%waitbar has been closed by the user
% call throw, return, or break
end
Hope it helps,
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With