Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keep Matlab from stepping into built in functions during dbstop if error

I use dbstop error a lot when working in Matlab. A good portion of the time, a mistake causes errors to be thrown inside of built-in [m-file] functions, which then causes Matlab to stop execution and open the file. However, it's almost never helpful to debug inside of the built-in file, so this ends up disrupting my workflow. Might there be a way to set things up so that Matlab backs out of the built-in file in the debugger (never opening it), leaving me at the function call?

like image 685
Evan Avatar asked Jan 03 '17 16:01

Evan


People also ask

How do I exit debug mode in MATLAB?

Run dbquit again to exit debug mode for buggy . Alternatively, dbquit all ends debugging for both files simultaneously.

What does a breakpoint do in MATLAB?

Setting breakpoints pauses the execution of your MATLAB® program so that you can examine values where you think an issue might have occurred. You can set breakpoints interactively in the Editor or Live Editor, or by using functions in the Command Window.

Which line of code resumes execution of a file following a stop in MATLAB?

dbcont resumes execution of a MATLAB® code file after pausing. Execution continues until another breakpoint is encountered, a pause condition is met, an error occurs, or execution completes successfully.

What is return MATLAB?

Description. return forces MATLAB® to return control to the invoking program before it reaches the end of the script or function. The invoking program is a script or function that calls the script or function containing the call to return .


1 Answers

Although I've never found a way to tackle this problem properly, it's fairly easy to hack together a workaround:

  1. Create a script containing something along these lines:

    S = dbstack();
    
    file_paths  = cellfun(@which, {S.file}, 'UniformOutput', false);
    builtins    = ~cellfun('isempty', strfind(file_paths, matlabroot()));
    stack_depth = find(~builtins, 1, 'first');
    
    for ii = 1:stack_depth-1
        dbup(); end
    
  2. Save it somewhere that makes sense to you, and place a shortcut to it in the MATLAB toolbar.

Then, whenever this problem occurs, you just click on your little shortcut, which will automatically take you to the first non-builtin function in the debug stack.

like image 125
Rody Oldenhuis Avatar answered Oct 03 '22 12:10

Rody Oldenhuis