I'm trying to find an error in my code. The error is in a function of 3rd level that initially works perfectly, but somehow at one point stops (the function is called many times within a loop).
The error says the variable is undefined (it doesn't happen at the beginning, but after more than 150 times). Could I write some condition atop the sentence to stop it just before the error? Then I could know why this variable is not defined anymore.
Use dbstop if error
. That dbstop
command will take you to command prompt in the stopped function when the error occurs.
You can also get tricky and use the dbstop in FILESPEC at LINENO if EXPRESSION
syntax. For example, if you want to break if the variable doesn't exist right before the line that trips the error, say line 224 of myFun.m
:
dbstop in myFun.m at 224 if ~exist('x','var')
Then it will stop at line 224 of myFun.m
if x
is not a variable.
Type
dbstop if error
then execute you code.
See doc of dbstop
for more options.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With