フィルターのクリア

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

1 回表示 (過去 30 日間)
Julian
Julian 2012 年 1 月 25 日
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.

採用された回答

Sean de Wolski
Sean de Wolski 2012 年 1 月 25 日
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 件のコメント
Sean de Wolski
Sean de Wolski 2012 年 1 月 25 日
I've submitted an enhancement request regarding this behavior.
Julian
Julian 2012 年 1 月 26 日
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.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeStartup and Shutdown についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by