Search code examples
matlabbreakpoints

Breakpoint in section of Matlab


I have written a MATLAB code defined in different sections. After running the first section of my code I would like to be able to debug subsequent sections using breakpoints. For some reason, however, when I add a breakpoint and use the "Run Section" command the debug mode is not triggered. It appears that I'm unable to run the beginning of the program and then use a breakpoint and the "Run Section" command. Does anyone know how to do this? I'm doing this to save time since the beginning of my program takes a long time to run. Thanks.


Solution

  • There are a couple of work-arounds I can think of which might help you.

    First, when you get to your breakpoint, save the entire workspace to a .mat file. Then comment out all the code up to this point and add a line to load your .mat file. You can now get to the point in your code you are debugging quickly.

    Another way to do it would be to put all the code past your breakpoint in a separate script. Then when you hit the breakpoint, you can set more breakpoints in the second script and call it from the command window as many times as you need.