Matlab:如何捕获警告 [英] Matlab: How to catch warning
问题描述
我正在MATLAB中运行一些数据处理工作,而求解器使用BACKSLASH运算符.有时,我会收到这样的警告:
I am running some data processing work in MATLAB and solver uses BACKSLASH operator. Sometimes, I get warning like this:
Warning: Rank deficient, rank = 1390, tol = 1.335195e-010.
Warning: Rank deficient, rank = 1386, tol = 1.333217e-010.
我想抓住那些警告.
我正在尝试将警告转换为错误,然后按照标题诱捕警告"中的说明进行捕获:
I would like to catch those warnings. I am trying to convert warning to error and then catch it as described here under title "Trapping warnings": http://undocumentedmatlab.com/blog/trapping-warnings-efficiently In the example, following string has been used to convert warning to error:
s = warning('error', 'MATLAB:DELETE:Permission');
但是,我不确定用于我的情况的字符串.我尝试使用
However, I am not sure what string to use for my case. I tried using
s = warning('error', 'Warning: Rank deficient’);
但是,它没有用. 任何帮助将不胜感激.
But, it did not work. Any help would be appreciated.
关于, DK
推荐答案
您需要指定警告 identifier ,而不是警告文本.您可以使用lastwarn
的两个输出形式找到标识符:
You need to specify the warning identifier, not the warning text. You can find the identifier using the two-output form of lastwarn
:
[msgstr, msgid] = lastwarn
在您的情况下,我认为您想要的标识符是'MATLAB:rankDeficientMatrix'
.
In your case, I think the identifier you want is 'MATLAB:rankDeficientMatrix'
.
这篇关于Matlab:如何捕获警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!