Do you think this behaviour of built-in functions error() and warning() is odd

1 view (last 30 days)
I find that warning('message', a1, a2,...) treats args a1 etc differently to warning('message_id', 'message', a1, a2, ..., an). The same is true for error but a surprise to me. I discovered this when I tried to show the size of an array in the warning by using size(X) as one of the arguments. What do you reckon to this behaviour, which I found after MLINT nagged me to add a message identifier but coughed when I did? Example shown below:
>> warning('%d %d', [1 2])
Warning: 1 2
>> warning('msg:id', '%d %d', [1 2])
??? Error using ==> warning
Formatted arguments cannot be non-scalar numeric matrices.

Accepted Answer

Sean de Wolski
Sean de Wolski on 25 Jan 2012
It means exactly what it says:
warning('msg:id', '%d %d', 1, 2)
Use 1,2 as scalars.
I do see how this differs from sprintf() where the former was acceptable.
sprintf('%d %d', [1,2])
  4 Comments
Julian
Julian on 26 Jan 2012
I did not appreciate you were with TMW; thanks for putting in an an enhancement request - so I accept your answer. I would add that making enhancement requests more visible and open to comment would be very welcome - either via MATLAB Central or through the private support web-site. Quite a lot of discussion in Answers in this domain - and I hate to submit enhancement requests.

Sign in to comment.

More Answers (0)

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!