Main Content

Concatenation Examples

Combining Single and Double Types

Combiningsinglevalues withdoublevalues yields asingle矩阵。Note that5.73*10^300is too big to be stored as asingle, thus the conversion fromdoubletosinglesets it to infinity. (Theclassfunction used in this example returns the data type for the input value).

x = [single(4.5) single(-2.8) pi 5.73*10^300] x = 4.5000 -2.8000 3.1416 Inf class(x) % Display the data type of x ans = single

Combining Integer and Double Types

Combining integer values withdoublevalues yields an integer matrix. Note that the fractional part ofpiis rounded to the nearest integer. (Theint8function used in this example converts its numeric argument to an 8-bit integer).

x = [int8(21) int8(-22) int8(23) pi 45/6] x = 21 -22 23 3 8 class(x) ans = int8

Combining Character and Double Types

Combiningcharactervalues withdoublevalues yields acharacter矩阵。MATLAB®converts thedoubleelements in this example to theircharacterequivalents:

x = ['A' 'B' 'C' 68 69 70] x = ABCDEF class(x) ans = char

Combining Logical and Double Types

Combininglogicalvalues withdoublevalues yields adouble矩阵。MATLAB转换logicaltrueandfalseelements in this example todouble:

x = [true false false pi sqrt(7)] x = 1.0000 0 0 3.1416 2.6458 class(x) ans = double