How to debug at command window in MATLAB

One of the killer features of MATLAB is its excellent debugging features in GUI mode. Anyone who has used the Visual Studio debugger will be right at home in MATLAB, since the keyboard shortcuts and mouse operations for debugging are the same. However, sometimes you may be using MATLAB in its -nodesktop mode where you only have access to its command window.

In these situations, you can still debug MATLAB scripts using the debugging commands:

  • dbstop in foo.m at 600: Set breakpoint in foo.m file at line 600.
  • dbstop if error: Indicate MATLAB that you want debugging to be stopped at the instructions that caused an error.
  • dbstatus: List all the breakpoints that are currently set.
  • dbclear all: Remove all breakpoints.
  • dbclear in foo.m: Remove all breakpoints in foo.m.
  • dbclear in foo.m at 600: Remove breakpoint set in foo.m at line 600.
  • dbcont: Continue execution until next breakpoint.
  • dbquit: Exit debug mode. Execution will be terminated.
  • dbstack: List the function call stack.
  • dbstep: Execute next instruction. Same as F10 in Visual Studio.
  • dbstep in: Step into next instruction. Same as F11 in Visual Studio.
  • dbstep out: Step out of next instruction. Same as Shift-F11 in Visual Studio.
  • To print the value of any variable, just type its name.
  • size: Get the size of any variable.
  • whos: Get the list of variables at current scope.

Reference: Debugging documentation of MATLAB

One thought on “How to debug at command window in MATLAB

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.