int8(3) vs int(3)
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Galen Elias
am 5 Apr. 2015
Kommentiert: Galen Elias
am 6 Apr. 2015
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?
0 Kommentare
Akzeptierte Antwort
Hugo
am 5 Apr. 2015
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.
Weitere Antworten (1)
Geoff Hayes
am 5 Apr. 2015
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.
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!