Documentation Center

  • Trials
  • Product Updates

Combining Unlike Integer Types


If you combine different integer types in a matrix (e.g., signed with unsigned, or 8-bit integers with 16-bit integers), MATLAB® returns a matrix in which all elements are of one common type. MATLAB sets all elements of the resulting matrix to the data type of the left-most element in the input matrix. For example, the result of the following concatenation is a vector of three 16-bit signed integers:


MATLAB also displays a warning to inform you that the result may not be what you had expected:

A = [int16(450) uint8(250) int32(1000000)];
Warning: Concatenation with dominant (left-most) integer class 
may overflow other operands on conversion to return class.

You can disable this warning by entering the following two commands directly after the operation that caused the warning. The first command retrieves the message identifier associated with the most recent warning issued by MATLAB. The second command uses this identifier to disable any further warnings of that type from being issued:

[msg, intcat_msgid] = lastwarn;
warning('off', intcat_msgid);

To re-enable the warning so that it will now be displayed, use

warning('on', intcat_msgid);

You can use these commands to disable or enable the display of any MATLAB warning.

Example of Combining Unlike Integer Sizes

After disabling the integer concatenation warnings as shown above, concatenate the following two numbers once, and then switch their order. The return value depends on the order in which the integers are concatenated. The left-most type determines the data type for all elements in the vector:

A = [int16(5000) int8(50)]
A =
   5000   50

B = [int8(50) int16(5000)]
B =
   50   127


The same rules apply to vertical concatenation:

C =


Example of Combining Signed with Unsigned

Now do the same exercise with signed and unsigned integers. Again, the left-most element determines the data type for all elements in the resulting matrix:

A =
   -100   100

B =
   100   0



A =
  50    0
Was this topic helpful?