Breakpoints required for code to work correctly?

6 views (last 30 days)
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

Accepted Answer

Fangjun Jiang
Fangjun Jiang on 10 Aug 2011
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.
  2 Comments
Sean
Sean on 10 Aug 2011
Thanks Jiang,
Yes, the problem was that the progress bar wasn't closing. I put a pause in just after the delete as you suggested and it seems to work. Do you know why this is necessary? It seems like the figure should already have been deleted by the time the pause executes...
Fangjun Jiang
Fangjun Jiang on 10 Aug 2011
You might have some busy operation after the chunk of the code you posted. It's like the computer is too busy to refresh the graphics. I think the same thing happens to the Windows OS too. Help drawnow might give you some idea. I don't know the details. It happened to me too. That's why I could guess your problem.

Sign in to comment.

More Answers (0)

Categories

Find more on Environment and Settings 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!