Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

Valid Combinations of Unlike Classes

Matrices and arrays can be composed of elements of most any MATLAB® data type as long as all elements in the matrix are of the same type. If you do include elements of unlike classes when constructing a matrix, MATLAB converts some elements so that all elements of the resulting matrix are of the same type.

Data type conversion is done with respect to a preset precedence of classes. The following table shows the five classes you can concatenate with an unlike type without generating an error (that is, with the exception of character and logical).

TYPE

character

integer

single

double

logical

character

character

character

character

character

invalid

integer

character

integer

integer

integer

integer

single

character

integer

single

single

single

double

character

integer

single

double

double

logical

invalid

integer

single

double

logical

For example, concatenating a double and single matrix always yields a matrix of type single. MATLAB converts the double element to single to accomplish this.

Related Topics

Was this topic helpful?