Can't set breakpoints on changed m-file

I run a numerical simulation called "myfile.m". Then I accidentally changed the code of "myfile.m", by accidentally inserting a character somewhere. The file now has an asterisk "myfile.m*". By itself not a big issue, but now I can't debug anymore :( Setting breakpoints gives a gray bullet instead of a red one. And it says "Save file to synchronize breakpoints". When I press "save", it says "Cannot save myfile.m while it is being debugged. Exit debug mode and save?" .... I am kinda scared to do this, because I remember having pressed this before and the whole simulation stopped, not just the debugging. And I don't know what is meant by "Exit debug". I am not debugging anyway. The simulation has been running for 24 hours, and the last time the red bulletpoints worked it showed some very good intermediate results, so I really don't want to waste them. But it will go on for another 24 hours, and I don't have the time, so I want to save the intermediate results stored in the variables, which I can only access using the breakpoints, right?

 Accepted Answer

Jan
Jan on 28 Apr 2017
When you have any breakpoints in the code, Matlab runs in debug mode. As a side-effect this disables the JIT acceleration and the code might run 4 or 100 times slower. Therefore the debug mode should be active only for debugging, but not for an interactive control of a productive program execution. It is too dangerous to insert a key by accident (as in your case) and confuse the system of computer and user. You are right: If you press "exit debug mode" the complete program is stopped and all changes are lost.
The formerly existing breakpoints work even if you have changed the file but did not save it. Then you cannot set new breakpoints and if you have inserted new lines, the editor might look like it stops in the wrong lines, because it uses the breakpoint-lines of the formerly saved code. This does not impede the porgram execution, only the display in the editor, but this is confusing enough.
My suggestion is: Do not run your code in debug mode for productive work.

2 Comments

Thanks a lot for this detailed answer. It helped me a lot.
+1 for a good explanation

Sign in to comment.

More Answers (2)

I would have used control-Z (or, in OS-X, command-Z) in order to Undo the change to the file. That would make the editor happy.

1 Comment

good point. Actually I wonder why this didn't occur to me :)

Sign in to comment.

Marloeys
Marloeys on 27 Apr 2017
I think I kind of solved the problem. The breakpoint worked anyway.

Categories

Find more on Environment and Settings in Help Center and File Exchange

Asked:

on 27 Apr 2017

Commented:

on 28 Apr 2017

Community Treasure Hunt

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

Start Hunting!