How to identify an iteration that throws a warning/error?

조회 수: 3 (최근 30일)
Oliver Johnson
Oliver Johnson 2016년 2월 12일
댓글: Image Analyst 2016년 2월 13일
I have a for-loop and some iterations are throwing warnings. I would like to know which iterations are the ones throwing the warning. Here is what I have tried:
errclass = zeros(1,nODF);
lastwarn(''); % reset warning state
for i = 1:nODF
DO STUFF (including computing eigenvalues of a matrix)
% check for error
[warnmsg, msgid] = lastwarn;
if ~strcmp(msgid,'')
errclass(i) = 1;
end
lastwarn(''); % reset warning state
end
However, when I evaluate sum(errclass) I get that only 8 warnings were thrown. As you can see in the attached document, which is what I see in the command window, there are far more than 8 warnings thrown, so this is somehow missing many of the warnings. Any suggestions?

답변 (2개)

Image Analyst
Image Analyst 2016년 2월 12일
Try
dbstop if warning
or else just step through a line at a time until the warning gets printed in the command window.
  댓글 수: 2
Oliver Johnson
Oliver Johnson 2016년 2월 12일
I want the entire loop (nODF is quite large) to run and then be able to do the analysis after (I plan to exclude the data corresponding to the iterations that threw warnings). So dbstop doesn't seem to help here, since it will require user interaction, right?
Image Analyst
Image Analyst 2016년 2월 13일
If you want to turn off warnings, read the comments in the attached file and see how I do it for some warnings I want to suppress. The comments will tell you how to suppress the warning.

댓글을 달려면 로그인하십시오.


Walter Roberson
Walter Roberson 2016년 2월 12일
"DO STUFF" might be throwing multiple warnings for the same iteration. That would make the number of emitted warnings larger than the number of iterations for which warnings were counted.

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by