MATLAB: Breakpoints required for code to work correctly

breakpointdeletedifferent resultexecutiongui figure

I have inherited a piece of code (m-file function) that works fine on its own, but when I used it inside other m-files it only works if I put a breakpoint in it. The section that doesn't seem to work without breakpointing is:
% If task completed, close figure and clear vars, then exit
if percentdone == 100 % Task completed
delete(progfig) % Close progress bar
%change the close request function back to normal
%set(progfig,'CloseRequestFcn','closereq');
% Clear persistent vars
clear progfig progpatch starttime lastupdate firstIteration
return
end
Can anyone help me understand why a breakpoint should change the behavior of this code? Specifically, the line 'delete(progfig) does not seem to execute unless there is a breakpoint somewhere within the if statement.
Thanks in advance, Sean

Best Answer

What do you mean "doesn't seem to work"? Any error messages? If you don't have break point, is it that the progress bar didn't close? Situation like that might happen. You might want to add a line "pause(0.1);" or "drawnow;" after the delete(progfig) line.
Related Question