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

1 visualización (últimos 30 días)
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.

Respuesta aceptada

Sean de Wolski
Sean de Wolski el 25 de En. de 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 comentarios
Sean de Wolski
Sean de Wolski el 25 de En. de 2012
I've submitted an enhancement request regarding this behavior.
Julian
Julian el 26 de En. de 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.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Startup and Shutdown en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by