Using try/catch to get warning message
Mostrar comentarios más antiguos
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 comentarios
Geoff Hayes
el 22 de Jul. de 2014
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
el 22 de Jul. de 2014
Editada: Douglas Alves
el 22 de Jul. de 2014
Respuesta aceptada
Más respuestas (1)
Image Analyst
el 22 de Jul. de 2014
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
Categorías
Más información sobre Data Type Identification en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!