필터 지우기
필터 지우기

int8(3) vs int(3)

조회 수: 2 (최근 30일)
Galen Elias
Galen Elias 2015년 4월 5일
댓글: Galen Elias 2015년 4월 6일
When I try run int(3), or int('b') I get an error: Undefined function 'int' for input arguments of type 'char'.
But when I run int8(3) or int8('b') (or any other int type) I get the expected results. Why?

채택된 답변

Hugo
Hugo 2015년 4월 5일
At least in Matlab 2015, the function "int" is related to filters (in the filtstates package) or integration (in the symbolic package) but not to casting data types.
The functions for converting data, including "int8" are described in
MATLAB > Language Fundamentals > Operators and Elementary Operations > Arithmetic > Integers
in the Matlab documentation.
Hope this helps.
  댓글 수: 1
Galen Elias
Galen Elias 2015년 4월 6일
Thanks for your help!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Geoff Hayes
Geoff Hayes 2015년 4월 5일
Galen - int is not a built-in MATLAB function. In the Command Window, type
which int -all
and you will see the message
'int' not found.
This makes sense because in order to cast something to an integer you need to specify the number of bits used in that (new) integer. That is why int8 works as it will convert a value to an 8-bit signed integer. Likewise, there exist functions to convert/cast the data to 16-, 32-, and 64-bit signed integers. Equivalent functions exist for converting/casting to unsigned integers.
  댓글 수: 1
Galen Elias
Galen Elias 2015년 4월 6일
Great answer thank you so much

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by