Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Customize dbstop in MATLAB

Is it possible to add a customized dbstop condition to Matlab?

Recently I found myself with out of bounds values in multiple variables, one way to track down the first occurance of this would be to set a conditional breakpoint on each line where these values are updated. However, I hope there is an easier way to do this.

I have recently had to track down a NaN which was fairly trivial due to:

dbstop if naninf

Hence I hope that it is possible to get something like:

dbstop if anything outside myBound

or

dbstop if myVariable outside myBound

I would of course be willing to take the performance hit that one may expect.

like image 324
Dennis Jaheruddin Avatar asked Jan 08 '14 12:01

Dennis Jaheruddin


People also ask

How do you set a break point in MATLAB?

A standard breakpoint pauses at a specific line in a file. To set a standard breakpoint, click the gray area to the left of the executable line where you want to set the breakpoint. Alternatively, you can press the F12 key to set a breakpoint at the current line.

What is Editor Debugger in MATLAB?

The Editor/Debugger provides a graphical user interface for text editing, as well as for M-file debugging. To create or edit an M-file use File -> New or File -> Open, or use the edit function. You can use any text editor to create M-files, such as Emacs.

How do I get out of debug mode in MATLAB?

To exit debug mode, press Alt+B followed by D. at the Command Prompt to exit debug mode.


1 Answers

If you use the editor, you can set a stop as normal, right-click on it, select "set/modify condition" and enter the condition (the stop will turn from red to yellow).

From command line, you can use

dbstop in file if expression
dbstop in file at location if expression

e.g.
dbstop in myFile at 200 if (~isempty(var) && var > 3)

as mentioned by @LuisMendo.

The second option may be more useful, since the first one seems to be only evaluated at the start of the file. In other words, it doesn't seem to be possible to have a similarly generic expression as dbstop if naninf that checks for certain values across an entire file.

like image 113
Jonas Avatar answered Sep 23 '22 17:09

Jonas