MATLAB: Can’t set breakpoints on changed m-file

access-variablesbreakpointsdebuggingsave

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?

Best Answer

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.