Programming Previous page   Next Page

Numeric Types

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:

Integers

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:

Data Type
Range of Values
Conversion Function
Signed 8-bit integer
-27 to 27-1
int8
Signed 16-bit integer
-215 to 215-1
int16
Signed 32-bit integer
-231 to 231-1
int32
Signed 64-bit integer
-263 to 263-1
int64
Unsigned 8-bit integer
0 to 28-1
uint8
Unsigned 16-bit integer
0 to 216-1
uint16
Unsigned 32-bit integer
0 to 232-1
uint32
Unsigned 64-bit integer
0 to 264-1
uint64

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.


Previous page  Overview of MATLAB Data Types Floating-Point Numbers Next page

© 1994-2005 The MathWorks, Inc.