Hi,
you can use lastwarn to get the last warning:
[warnmsg, msgid] = lastwarn
And than you can compare the msgid from the last warning with the msgid from the warning which you get for a bad matrix.
>> inv([eps eps; eps eps])
Warning: Matrix is singular to working precision.
ans =
Inf Inf
Inf Inf
>> [warnmsg, msgid] = lastwarn
warnmsg =
Matrix is singular to working precision.
msgid =
MATLAB:singularMatrix
So you do something like this in your code:
inv(input_from_user)
[warnmsg, msgid] = lastwarn
if strcmp(msgid,'MATLAB:singularMatrix')
//warning was thrown, do something
end
Best Answer