8.5. MATLAB Data Types#
Variables can store different types of data which are used to do different things.
Data type |
Description |
---|---|
Integer |
Integer values, e.g., |
Float |
Floating point values (decimals), e.g., |
Complex |
Complex numbers, e.g., |
Boolean |
Boolean values, e.g., |
String |
Character string, e.g., |
MATLAB automatically use the appropriate data type for the value being assigned to a variable.
8.5.1. Casting data types#
We can change the data type for a variable using casting with the following functions
int32()
- returns an 32-bit integer number from an input of a floating point number or string (similar functions areint8()
,int16()
andint64()
)double()
- returns a floating point number from an input of an integer or stringstring()
- returns a string from a range of data types.
Lets try casting between different data types. Enter the following commands into the console.
>> int32(1.23)
ans =
int32
1
>> double(123)
ans =
123
>> string(123)
ans =
"123"
>> string(1 + 2j)
ans =
"1+2i"