我在交互式 MATLAB 控制台中发出以下命令:
>> foo = [1 inf];
>> dbstop if naninf
>> foo
我现在有奇怪的行为:MATLAB 似乎分成两个不同的文件,但实际上并没有停止执行。这很慢,因为编辑器会在这两个文件之间反复切换,Ctrl+C 不执行任何操作。输出是:
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
...
...
然后它最终以调试提示停止,并带有一个非常长的(递归)堆栈,例如:
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
...
...
在我尝试调试的真实程序中,我得到了相同的结果,但更糟糕的是,有时我遇到了递归限制错误并中止,有时 MATLAB 完全崩溃了。我真的很想能够使用dbstop if naninf
,但这几乎不可能,这让我很难过。有什么建议吗?
在 Linux 上使用 MATLAB 2009b 64 位。
谢谢!
编辑:
我刚刚在 MATLAB 2007b 32 位 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
所以这里 dbstop 如果 naninf 在故意将 inf 分配给变量时似乎没有做任何事情。文档说:
dbstop if naninf 或 dbstop if infnan 当您随后运行的任何 MATLAB 程序文件由于运算符、函数调用或标量赋值产生无限值 (Inf) 或非数字 (NaN) 值时停止执行,将MATLAB 处于调试模式,在遇到 Inf 或 NaN 的行之后立即暂停。
即使我故意将 inf 分配给变量(如上面的 t = foo(2) 或 s = inf)或者“标量分配”是什么意思,这难道不应该命中吗?