Concatenation Examples
Combining Single and Double Types
Combiningsingle
values withdouble
values yields asingle
矩阵。Note that5.73*10^300
is too big to be stored as asingle
, thus the conversion fromdouble
tosingle
sets it to infinity. (Theclass
function 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 withdouble
values yields an integer matrix. Note that the fractional part ofpi
is rounded to the nearest integer. (Theint8
function 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
Combiningcharacter
values withdouble
values yields acharacter
矩阵。MATLAB®converts thedouble
elements in this example to theircharacter
equivalents:
x = ['A' 'B' 'C' 68 69 70] x = ABCDEF class(x) ans = char
Combining Logical and Double Types
Combininglogical
values withdouble
values yields adouble
矩阵。MATLAB转换logical
true
andfalse
elements in this example todouble
:
x = [true false false pi sqrt(7)] x = 1.0000 0 0 3.1416 2.6458 class(x) ans = double