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

1 Ansicht (letzte 30 Tage)
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.

Akzeptierte Antwort

Sean de Wolski
Sean de Wolski am 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 Kommentare
Sean de Wolski
Sean de Wolski am 25 Jan. 2012
I've submitted an enhancement request regarding this behavior.
Julian
Julian am 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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Startup and Shutdown finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by