问题
How can I attach to a running Matlab script (i.e. a m-file which I have executed with F5 ) ? It runs since days (I have an infinite while loop) and I want to understand what is wrong (it should exit it at some point). I know I can rerun it and set a breakpoint but that is not what I am asking. I wanna set a breakpoint NOW inside the loop and stop the process and debug it. Matlab does not allow me to set a breakpoint.
回答1:
Unfortunately Matlab does not allow this. To work around this problem I call this function at critical points in a project:
function cxdebug()
f='c:\cxdebug';
if exist(f,'file')
try, delete(f);end
keyboard;
end
end
Once you created the file, matlab will enter the debugger when the function is called next time.
来源:https://stackoverflow.com/questions/35183020/how-to-attach-to-a-running-matlab-script