Based on Rath's answer and reviews from Mathworks, this is the closest moment to you (R2016b):
S = dbstack('-completenames'); builtins = ~cellfun('isempty', strfind({S(:).file}, matlabroot())); stack_depth = find(~builtins, 1, 'first'); hDocument = matlab.desktop.editor.findOpenDocument(S(1).file); matlab.desktop.editor.openAndGoToLine(S(stack_depth).file,S(stack_depth).line); hDocument.close(); if stack_depth == 2 dbup(); end
This shortcut will be:
- Open the closest user function to the correct line.
- Close the built-in function that was opened on error.
- If the error occurred only at one level from the user-defined function, switch to this workspace.
The problem is that dbup () only works once - after the call, execution in the script ends. There is no function to switch to any place on the stack.
Evan
source share