Mathematics |
Integer Data Types
Integer data types in MATLAB take on integer values in a specified range. For example, an integer of type int8
can take any of the 28 possible values of signed 8-bit integers in the range -128
to 127
. Integer data types are useful for storing data that can be described using only integers, such as image files. The following table lists the integer data types that support arithmetic operations and their ranges.
To assign an integer data type to a number or variable, use one of the functions listed in the first column of the table. For example,
sets the value of x
to be 5
with data type int8
. You can verify the data type of the result using the class
command.
When you convert a number to one of the integer data types, MATLAB rounds the result to the nearest integer. For example,
For numbers that are halfway between two integers, MATLAB rounds up if the number is positive and rounds down if the number is negative. For example,
Integer Mathematics | Largest and Smallest Values for Integer Data Types |
© 1994-2005 The MathWorks, Inc.