Numeric classes in MATLAB® include signed and unsigned integers, and single-precision and double-precision floating-point numbers. By default, MATLAB stores all numeric values as double-precision floating point. (You cannot change the default type and precision.) You can choose to store any number, or array of numbers, as integers or as single-precision. Integer and single precision arrays offer more memory-efficient storage than double precision.
All numeric types support basic array operations, such as indexing, reshaping, and mathematical operations.
Create Numeric Variables
|8-bit signed integer arrays|
|16-bit signed integer arrays|
|32-bit signed integer arrays|
|64-bit signed integer arrays|
|8-bit unsigned integer arrays|
|16-bit unsigned integer arrays|
|32-bit unsigned integer arrays|
|64-bit unsigned integer arrays|
Convert Between Numeric Types
Query Type and Value
|Determine whether input is integer array|
|Determine if input is floating-point array|
|Determine whether input is numeric array|
|Determine whether array uses complex storage|
|Determine which array elements are finite|
|Determine which array elements are infinite|
|Determine which array elements are NaN|
Numeric Value Limits
|Floating-point relative accuracy|
|Largest consecutive integer in floating-point format|
|Create array of all |
|Largest value of specific integer type|
|Smallest value of specified integer type|
|Create array of all |
|Largest positive floating-point number|
|Smallest normalized floating-point number|
MATLAB represents floating-point numbers in either double-precision or single-precision format. The default is double precision.
This example shows how to perform arithmetic and linear algebra with single precision data.
MATLAB supports 1-, 2-, 4-, and 8-byte storage for integer data. If you use the smallest integer type that accommodates your data, you can save memory and program execution time.
This example shows how to perform arithmetic on integer data representing signals and images.
Create complex numbers. Complex numbers consist of a real part and an imaginary part.
MATLAB represents infinity by the special value
and values that are neither real nor complex by the special value
which stands for “Not a Number”.
You can check the data type of a variable using any of these commands.
format function or set Preferences to control the display
of numeric values.
If you combine different integer types in a matrix (e.g., signed with unsigned, or 8-bit integers with 16-bit integers), all elements of the resulting matrix are given the data type of the leftmost element.
If you combine integers with
logical classes, all elements of the resulting
matrix are given the data type of the leftmost integer.
If you construct a matrix using empty matrix elements, the empty matrices are ignored in the resulting matrix.
These examples show how to concatenate different data types.
Specify hexadecimal and binary values either as literals or as text. Hexadecimal and binary literals are stored as integers. You can convert text representing hexadecimal and binary values to numbers, and numbers to text representations.