How to close a wiatbar when an error occurs before the delete command?
Show older comments
Hello All, In my script I have put a waitbar for intimating the user the current number of the calculation. The code goes like this:
pvh=waitbar(0,'calculating.....','name','LOSS ESTIMATION',...
'createcancelbtn','setappdata(pvh,''cancel_callback'',1)');
setappdata(pvh,'cancel_callback',0);
for count_i1 = 1:lako_count
% If the calculation is cancelled exit the FOR loop.
if getappdata(pvh,'cancel_callback')
errordlg('calculation Stopped by user');
break;
end
waitbar(count_i1/ lako_count,pvh,sprintf('Calculating %d %s %d',count_i1,'of', lako_count)); %progress bar for lako_count calculations
... so on the rest of the code goes and at the end I have delete (pvh); % To delete the waitbar fig at the end. This works fine. But one problem what I saw is, say for example if due to some error at other part of the code, the script stops before delete (pvh)and I will get the error but the waitbar doesnt close unless I enter delete() or close all force in the command window manually. Is there a method where when error occurs at any part of the code the waitbar also can be made to close automatically? I looked into try catch method but the problem I will not know what error occured/interrupted the program. I looked into oncleanup also but couldnt get much .
can someone please guide me on what can be done? thanks in advance
Accepted Answer
More Answers (0)
Categories
Find more on App Building in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!