it says error using assert, assertion failed and error in iuntitled (line 10) assert(ischar(in))
이전 댓글 표시
error using assert
Assertion failed
Error in iuntitled (line 10)
assert(ischar(in))
댓글 수: 3
Geoff Hayes
2022년 6월 16일
@Ian - did you add the assert? Or is it being called from some other piece of code? If other code, can you post the code to this question?
If in is not a character, then ischar(in) will be false and the assert is indicating this. See assert for details on how this function behaves with false input parameter.
Ian
2022년 6월 16일
편집: Geoff Hayes
2022년 6월 17일
Ian
2022년 6월 16일
답변 (2개)
Geoff Hayes
2022년 6월 17일
@Ian - as per the function comment, Encode a single character i. I suspect that you are passing something else i.e. a numeric value like
>> encodeCharacter(42)
Error using encodeCharacter (line 8)
Assertion failed.
Try doing
>> encodeCharacter('4')
ans =
'1010001110101110'
or any other character. Note that you can only pass in one character. If you pass in 2 or more, then a different assert will fire.
That is what an assert does. If the assertion fails (here that means that in is not a char), then an error is thrown and the message 'Assertion failed.' is thrown.
% Assertion is true -> no error
in = '5';
assert(ischar(in))
% Assertion is false -> error
in = 5;
assert(ischar(in))
댓글 수: 2
Daniel Lyddy
2023년 12월 15일
I hate the fact that it prints "Error using assert." That misleads developers into thinking they've coded up their assert() lines incorrectly.
I just want to print my own error message. The other stuff is confusing to my end users, and should only be printed as a default if I have not provided my own error message.
@Daniel Lyddy: it is also strangely inconsistent: ERROR does not state "Error using error":
error('some text')
MATLAB versions until at least R2021a did not include the text "Error using assert", so it is a recent change:

Apparently someone meddled in something that worked perfectly. My guess is that new text was introduced with this behavior change in R2022a:
A related topic, where someone meddled with ERROR to try and "improve" it... thus rendering it useless:
카테고리
도움말 센터 및 File Exchange에서 Graphics Object Programming에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!