필터 지우기
필터 지우기

Using try/catch to get warning message

조회 수: 39 (최근 30일)
Douglas Alves
Douglas Alves 2014년 7월 22일
댓글: Kelly Kearney 2014년 7월 22일
What o I have to do in order to get rid of the message in ode45 line 309 (error tolerance message). I use try and then I put the ode45(......) and eventually I`ll have a warning message about the tolerance for integration on the screen but I do not want this warning poping up all the time so I save the line 309 in ode45 and put it in a catch statement but it didnt work. Can you guys help me with that.
  댓글 수: 2
Geoff Hayes
Geoff Hayes 2014년 7월 22일
What is the full warning message? What is your line of code?
The try/catch will only be useful to capture thrown errors and will not suppress a warning message.
Douglas Alves
Douglas Alves 2014년 7월 22일
편집: Douglas Alves 2014년 7월 22일
The line is in ode45 309 which is "warning(message('MATLAB:ode45:IntegrationTolNotMet', sprintf( '%e', t ), sprintf( '%e', hmin )));" This happens once every each run it doesnt represent anything bad actually but it's annoying so I want to suppress it.

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

채택된 답변

Kelly Kearney
Kelly Kearney 2014년 7월 22일
You can turn off specific warning messages via the warning command:
S = warning('MATLAB:ode45:IntegrationTolNotMet', 'off');
... add your ode call here ...
warning(S);
  댓글 수: 2
Douglas Alves
Douglas Alves 2014년 7월 22일
Thank you very much Kelly that works... I just had to put 'off' in front of the message inside S. I guess it'`s because of the MATLAB version.
Kelly Kearney
Kelly Kearney 2014년 7월 22일
Oops, as you can see from IA's answer below, I reversed the inputs (ugh, I always do that with this command in my code too).
Should be
S = warning('off', 'MATLAB:ode45:IntegrationTolNotMet');

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

추가 답변 (1개)

Image Analyst
Image Analyst 2014년 7월 22일
Here's a useful function I run at the beginning of my larger m-files. It gives instructions for how to find out the error message and how to turn it off. It will be easy to adapt it to your message. The actual file is attached below this:
% http://www.mathworks.com/help/matlab/matlab_prog/suppress-warnings.html
function TurnOffWarnings
try
% To set the warning state, you must first know the message identifier for the one warning you want to enable.
% Query the last warning to acquire the identifier. For example:
% warnStruct = warning('query', 'last')
% messageID = warnStruct.identifier
% messageID =
% MATLAB:concatenation:integerInteraction
% Turn off this warning "Warning: Image is too big to fit on screen; displaying at 33% "
warning('off', 'Images:initSize:adjustingMag');
% Get rid of warning about directory already existing:
% "Warning: Directory already exists."
warning('off', 'MATLAB:MKDIR:DirectoryExists');
% Turn off note "Warning: Added specified worksheet." that appears in the command window.
warning('off', 'MATLAB:xlswrite:AddSheet');
% Get rid of warning about roipolyold being deprecated:
% "Warning: Function ROIPOLYOLD will be removed in the future. Use ROIPOLY instead"
warning('off', 'images:removing:function');
% Get rid of warning about wavread() being deprecated:
% "Warning: WAVREAD will be removed in a future release. Use AUDIOREAD instead."
warning('off', 'MATLAB:audiovideo:wavread:functionToBeRemoved');
catch ME
errorMessage = sprintf('Error in function %s() at line %d.\n\nError Message:\n%s', ...
ME.stack(1).name, ME.stack(1).line, ME.message);
fprintf(1, '%s\n', errorMessage);
WarnUser(errorMessage);
end
return; % from TurnOffWarnings

카테고리

Help CenterFile Exchange에서 Entering Commands에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by