Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Abort current script on closing waitbar

Tags:

matlab

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?

like image 405
dynamic Avatar asked Jan 23 '13 17:01

dynamic


2 Answers

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
like image 51
Jonas Avatar answered Sep 28 '22 21:09

Jonas


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,

like image 28
Kiran Avatar answered Sep 28 '22 22:09

Kiran