it says error using assert, assertion failed and error in iuntitled (line 10) assert(ischar(in))

30 ビュー (過去 30 日間)
error using assert
Assertion failed
Error in iuntitled (line 10)
assert(ischar(in))
  3 件のコメント
Ian
Ian 2022 年 6 月 16 日
can you help me with this

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

回答 (2 件)

Geoff Hayes
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.

Cris LaPierre
Cris LaPierre 2022 年 6 月 17 日
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))
Error using assert
Assertion failed.

カテゴリ

Find more on Environment and Settings in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by