Help using lastwarn.m

조회 수: 2 (최근 30일)
mathworks2011
mathworks2011 2012년 1월 4일
I have code which does:
[msgstr, msgid] = lastwarn;
warning('OFF', msgid);
dostuff(); %generates a waring message
warning('ON', msgid);
The problem with this is that I still get one waring message, as the last warn before dostuff() was called was a different message.
I dont want to turn all warnings off as this is slow.
I would have thought that I could hard code the warning I want to turn off, but this doesnt seem possible:
"Warning: Out of range or non-integer values truncated during conversion to character."
how can I use msgid to ensure I never see that warning when calling do stuff? (I dont want to fiddle with the GUI settings either).
thanks
  댓글 수: 1
Walter Roberson
Walter Roberson 2012년 1월 4일
If you are getting that warning, your code is very likely wrong. You should figure out why it is happening, and change your code to prevent those circumstances from arising. That might involve using a different data type, or using a cell array, or might involve using floor() or ceil() or fix() or round() so that it is only integral values that are submitted to char()

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

채택된 답변

mathworks2011
mathworks2011 2012년 1월 4일
>> [msgstr, msgid] = lastwarn;
>> msgstr
msgstr =
Out of range or non-integer values truncated during conversion to character.
>> msgid
msgid =
MATLAB:nonIntegerTruncatedInConversionToChar
so I have msgid. What are you suggesting I do with it?
something like:
warning('OFF), 'MATLAB:nonIntegerTruncatedInConversionToChar'); ?
thanks
  댓글 수: 1
Honglei Chen
Honglei Chen 2012년 1월 4일
Yes, warnging('off','MATLAB:nonIntegerTruncatedInConversionToChar'); I've also updated the answer above.

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

추가 답변 (1개)

Honglei Chen
Honglei Chen 2012년 1월 4일
You need to find out the corresponding id generated by dostuff. You can try to do this by first reset the warning state and then run dostuff and lastwarn
warning('');
dostuff();
[msgstr, msgid] = lastwarn;
warning('off',msgid);

카테고리

Help CenterFile Exchange에서 Dialog Boxes에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by