I issue following command in the interactive MATLAB console:
>> foo = [1 inf];
>> dbstop if naninf
>> foo
I now get weird behaviour: MATLAB seems to to break into two different files, but doesn’t actually stop execution. This is pretty slow because the editor switches between those two files repeatedly, Ctrl+C doesn’t do anything. Output is:
481 end
20 if ~isfloat(value)
20 if ~isfloat(value)
399 if numel(var) > numelLimit
20 if ~isfloat(value)
20 if ~isfloat(value)
399 if numel(var) > numelLimit
20 if ~isfloat(value)
20 if ~isfloat(value)
399 if numel(var) > numelLimit
...
...
it then finally stops with a debug prompt, with a really long (recursive) stack like:
dbstack
In codetools/private/dataviewerhelper>upconvertIntegralType at 20
In codetools/private/dataviewerhelper at 9
In workspacefunc>createComplexScalar at 271
> In workspacefunc>num2complex at 241
In workspacefunc>getShortValueObjectJ at 230
In workspacefunc>getShortValueObjectsJ at 349
In workspacefunc at 21
In codetools/private/dataviewerhelper>upconvertIntegralType at 20
In codetools/private/dataviewerhelper at 9
In workspacefunc>createComplexScalar at 271
In workspacefunc>num2complex at 241
In workspacefunc>getShortValueObjectJ at 230
In workspacefunc>getShortValueObjectsJ at 349
In workspacefunc at 21
In workspacefunc>getStatObjectsJ at 399
In workspacefunc at 27
In codetools/private/dataviewerhelper>upconvertIntegralType at 20
In codetools/private/dataviewerhelper at 9
In workspacefunc>createComplexScalar at 271
In workspacefunc>num2complex at 241
In workspacefunc>getShortValueObjectJ at 230
In workspacefunc>getShortValueObjectsJ at 349
In workspacefunc at 21
In codetools/private/dataviewerhelper>upconvertIntegralType at 20
In codetools/private/dataviewerhelper at 9
In workspacefunc>createComplexScalar at 271
In workspacefunc>num2complex at 241
In workspacefunc>getShortValueObjectJ at 230
In workspacefunc>getShortValueObjectsJ at 349
In workspacefunc at 21
In workspacefunc>getStatObjectsJ at 399
In workspacefunc at 27
...
...
In my real program I’m trying to debug I get the same but even worse so that sometimes I hit the recursion limit error and abort, sometimes MATLAB simply completely crashes. I would really like to be able to use dbstop if naninf, but this makes it pretty much impossible and this makes me sad. Any advice?
Using MATLAB 2009b 64 bit on Linux.
Thanks!
Edit:
I just tried it on MATLAB 2007b 32 bit Linux:
>> foo = [1 inf]
foo =
1 Inf
>> dbstop if naninf
>> foo
foo =
1 Inf
>> foo = [1 inf]
foo =
1 Inf
>>
>> t = foo(2)
t =
Inf
So here dbstop if naninf doesn’t seem to do anything when deliberately assigning inf to a variable. The docs say:
dbstop if naninf or dbstop if infnan stops execution when any MATLAB program file you subsequently run produces an infinite value (Inf) or a value that is not a number (NaN) as a result of an operator, function call, or scalar assignment, putting MATLAB in debug mode, paused immediately after the line where Inf or NaN was encountered.
Shouldn’t this hit even when I deliberately assign a inf to a variable (as in above t = foo(2) or s = inf) or what is meant by “scalar assignment”?
That weird deeply recursive breakpoint you’re seeing looks like you’re hitting breakpoints in the part of the Matlab GUI that is itself implemented in M-code, when it’s trying to display NaN or Inf values in your workspace. (This is one of the downsides of the Matlab IDE running in the Matlab VM along with user code.) I can reproduce. Try turning off the Workspace view in the Desktop menu, or switching to a minimal layout with Desktop > Desktop Layout > Command Window Only.
For the second part: the breakpoint won’t be hit for expressions entered directly at the command line. If you throw it in a script or function you’ll hit the breakpoint. For example:
When you invoke this function, it’ll break on (after, actually) lines 2 and 4.