I want to catch Warning: Matrix is close to singular or badly scaled, during a matrix division A/B.

 採用された回答

Adam
Adam 2018 年 9 月 19 日

4 投票

may help with this. Credit to Guillaume from this answer for the link.

その他の回答 (1 件)

Geoff May
Geoff May 2020 年 7 月 25 日

3 投票

You could use the lastwarn function to reset, then check the last warning. Granted this might not work if the warning you are interested in gets overwritten by a subsequent warning that you would rather discard.
% reset the lastwarn message and id
lastwarn('', '');
% call the function that might throw a warning
diceyFunction();
% now if a warning was raised, warnMsg and warnId will not be empty.
[warnMsg, warnId] = lastwarn();
% you can check the warning message or id, or just throw the warning as an error if desired
if(isempty(warnId))
noProblem();
else
error(warnMsg, warnId);
end

カテゴリ

ヘルプ センター および File ExchangeError Handling についてさらに検索

質問済み:

2018 年 9 月 19 日

回答済み:

2020 年 7 月 25 日

Community Treasure Hunt

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

Start Hunting!

Translated by