필터 지우기
필터 지우기

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

조회 수: 1 (최근 30일)
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 CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by