MATLAB Answers

detect debug mode

47 views (last 30 days)
Ronan on 13 Jul 2011
Answered: Julian on 9 Oct 2015
is there a way to tell if your function has been called from the "k>>" debug prompt instead of the normal ">>" prompt?
Something like an "isdebug()" function??


Sign in to comment.

Accepted Answer

Daniel Shub
Daniel Shub on 13 Jul 2011
I don't think there is a robust way to tell. For example, you can get the "k>>" prompt with a keyboard command and I have no idea how to tell if the keyboard command has been called.
If you just want to tell if you are at a standard break point you can probably check each item in dbstack against the breakpoints returned by dbstatus.

  1 Comment

Ronan on 13 Jul 2011
Thanks Daniel
If there really is no builtin way then comparing the outputs of dbstack an dbstatus is a good suggestion. Can anyone foresee and problems with this??

Sign in to comment.

More Answers (2)

Jan on 13 Jul 2011
You can use this to determine, if Matlab is currently in debug mode:
This replies 1 in debug mode, 0 otherwise. This is not documented and can change with the Matlab version.


Daniel Shub
Daniel Shub on 14 Jul 2011
I need to play around with the feature command more.
Ronan on 14 Jul 2011
Thanks Jan.
Just what I was after.

Sign in to comment.

Julian on 9 Oct 2015
I also needed an answer to this question! I was pleased just now to find here on Answers that feature('IsDebugMode') does the trick. Before turning to Answers I was looking in the MATLAB help, and came up with this alternative:
dbup % try going up the stack frame, works if in debug mode
dbdown % back to where we started
isDebugMode = true;
catch ME
assert(strcmp(ME.identifier, 'MATLAB:dbOnlyInDebugMode'))
isDebugMode = false;
Although the undocumented feature() is much neater, this is an alternative if you want to stay on official MATLAB.


Sign in to comment.

Sign in to answer this question.



Translated by