Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matlab warning('error') produces not enough arguments error

Tags:

matlab

I was trying to use the warning() function with a warning message. When I try warning('random message') it works perfectly fine. But if I change the string to error instead, I get an error saying it doesn't have enough input arguments:

warning('error')
Error using warning
Not enough input arguments.

Is there something special about the word error that prevents me from using it as a message?

I am using 2014b.

like image 679
sodiumnitrate Avatar asked May 09 '15 19:05

sodiumnitrate


1 Answers

Yes, the 'error' flag is a special undocumented option that requires an additional input (a message identifier). It is used for trapping/catching warnings as errors. See this Undocumented Matlab post and this MathWorks Newsgroup posting.

This issue can be replicated in R2015a as well. Perhaps this useful option should be documented or maybe warning('error') with no message identifier should just work as expected. You might consider filing a service request with The MathWorks.

However, it's probably a good habit to use the the two-input form of warning (and error) with the initial message ID. For example:

warning('MyFunction1:MyWarningName1','error')

or

warning('MyLibrary:MyFunction2:MyWarningName2','error')
like image 109
horchler Avatar answered Sep 18 '22 18:09

horchler