MATLAB: Is it possible to check warning message

checkfunctionmessagewarning

I would like to check if a function display a warning or not? Is it possible?

Best Answer

Try using lastwarn:
% Initialize the global lastwarn variable to "Success"
lastwarn('Success')
% Some code that may or may not produce an error
a=10;
% Check if a warning was issued.
if strcmp(lastwarn, 'Success')
% All is well - no warning.
fprintf('All is well - no warning.\n');
else
% A warning was issued.
fprintf('A warning was issued..\n');
end
Related Question