Breakpoints required for code to work correctly?

6 visualizaciones (últimos 30 días)
Sean
Sean el 10 de Ag. de 2011
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

Respuesta aceptada

Fangjun Jiang
Fangjun Jiang el 10 de Ag. de 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 comentarios
Sean
Sean el 10 de Ag. de 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 el 10 de Ag. de 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.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Environment and Settings en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by