How to clear "last warning"?

20 ビュー (過去 30 日間)
Benjamin
Benjamin 2012 年 5 月 31 日
コメント済み: Walter Roberson 2018 年 6 月 22 日
Hi!
SHORT QUESTION: I would like to clear the value "lastwarn" in a nice way so that I can create loops.
BACKGROUND: I want to count the number of warnings " Matrix is singular to working precision." that Matlab generates. I have read http://www.mathworks.com/matlabcentral/answers/32348-using-if-warning-as-a-conditional-statement But it does not say how to clear the last warning. Currently I am creating a new warning for this purpose (see the following code). Does anybody know a better solution?
vector_input=[0 1 0]';
vector_output= -100*ones(size(vector_input));
number_warnings=0;
for k=1:size(vector_input,1)
% warning on MATLAB:nearlySingularMatrix;
vector_output(k)=inv( vector_input(k));
[msglast, msgidlast] = lastwarn;
if strcmp(msgidlast,'MATLAB:singularMatrix')
number_warnings=number_warnings+1;
end
s = warning('off','all'); % turn display of all warnings off
warning('FineId','fine') % becomes the last warning
warning(s) % turn display of all warnings on
end

採用された回答

Honglei Chen
Honglei Chen 2012 年 5 月 31 日
warning('')
  2 件のコメント
Benjamin
Benjamin 2012 年 5 月 31 日
Thanks a lot Honglei Chen! I have just adapted your answer to the following
lastwarn('')
Walter Roberson
Walter Roberson 2018 年 6 月 22 日
Turns out to require lastwarn('') now.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeError Handling についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by