Debugging MATLAB: Break before an error at certain line

后端 未结 3 1497
萌比男神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 21:54

    Type

     dbstop if error
    

    then execute you code.

    See doc of dbstop for more options.

    0 讨论(0)
  • 2021-01-13 21:55

    Check to see if you are out of bounds of the array or other structure you are iterating over

    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题