Programming |
Numeric data types in MATLAB include signed and unsigned integers, and single- and double-precision floating-point numbers. Integer and single- precision arrays offer more memory efficient storage than double precision.
All numeric types support basic array operations, such as subscripting and reshaping. All numeric types except for int64
and uint64
can be used in mathematical operations.
This section covers the following topics:
MATLAB has four signed and four unsigned integer data types. Signed types enable you to work with negative integers as well as positive, but cannot represent as wide a range of numbers as the unsigned types because one bit is used to designate a positive or negative sign for the number. Unsigned types give you a wider range of numbers, but these numbers can only be zero or positive.
MATLAB supports 1-, 2-, 4-, and 8-byte storage for integer data. You can save memory and execution time for you programs if you use the smallest integer type that accommodates your data. For example, you don't need a 32-bit integer to store the value 100
.
Here are the eight integer data types, the range of values you can store with each type, and the MATLAB conversion function required to create that type:
Creating Integer Data
MATLAB stores numeric data as double-precision floating point by default. To store data as an integer, use one of the conversion functions shown in the table above:
You can use the whos
function to show the dimensions, byte count, and data type of an array represented by a variable:
Or you can use the class
function if you want to assign the output as shown here:
Use the isinteger
function if you just want to verify that x
is an integer:
The conversion functions are also useful when converting other data types, such as strings, to integers:
Integer Functions
See Integer Functions for a list of functions most commonly used with integers in MATLAB.
Overview of MATLAB Data Types | Floating-Point Numbers |
© 1994-2005 The MathWorks, Inc.