user34790
user34790

Reputation: 2036

Debugging in matlab

I want to know which line caused Matrix Close to Singular Warning in matlab. How can I do it? Right now I have lots of places where I try to invert the matrix. I want to know at which particular place it was raised.

Upvotes: 1

Views: 78

Answers (1)

chappjc
chappjc

Reputation: 30579

You can have the debugger stop automatically with a warning by typing the following command before running,

dbstop if warning

For example, I created a file called dbstopIfWarningTest.m with just one line, inv(zeros(3)), and when I run the function, it stops on that line:

>> dbstopIfWarningTest
Warning: Matrix is singular to working precision. 
> In dbstopIfWarningTest at 1 

Warning from dbstopIfWarningTest at 1
inv(zeros(3))
K>> 

Then you can look to see what the inputs are that are causing the warning.

Upvotes: 3

Related Questions