Debugging MATLAB: Break before an error at certain line

后端 未结 3 1498
萌比男神i
萌比男神i 2021-01-13 21:11

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

3条回答
  •  深忆病人
    2021-01-13 22:06

    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.

提交回复
热议问题