I am running some data processing work in MATLAB and solver uses BACKSLASH operator. Sometimes, I get warning like this:
Warning: Rank deficient, rank = 1390, tol = 1.335195e-010.
Warning: Rank deficient, rank = 1386, tol = 1.333217e-010.
I would like to catch those warnings. I am trying to convert warning to error and then catch it as described here under title “Trapping warnings”: http://undocumentedmatlab.com/blog/trapping-warnings-efficiently In the example, following string has been used to convert warning to error:
s = warning('error', 'MATLAB:DELETE:Permission');
However, I am not sure what string to use for my case. I tried using
s = warning('error', 'Warning: Rank deficient’);
But, it did not work. Any help would be appreciated.
Regards, DK
Using the undocumented syntax warning('error', 'mycomponent:myMessageID') will tell MATLAB to convert the warning to an error, which you can then catch with a try-catch block and handle appropriately: You can find the message ID for your warning using lastwarn just after it occurs.
MATLAB now issues a warning. Turn off the most recently invoked warning with warning('off','last') .
You can selectively enable or disable specific warning messages, as long as they have been given a message identifier, with the WARNING function using the state and 'message_id' input arguments. You can suppress all warning messages using the 'off' state option, with the argument 'all' in place of a message identifier.
filter(e => typeof e == 'string'); for(m in messages){ if(messages[m]. indexOf('The warning I am looking for...') != -1){ //treat the warning as you want //you could use switch case if you want }; }; return console.
You need to specify the warning identifier, not the warning text. You can find the identifier using the two-output form of lastwarn
:
[msgstr, msgid] = lastwarn
In your case, I think the identifier you want is 'MATLAB:rankDeficientMatrix'
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With