Section: Type Cast Functions
y = dcomplex(x)
where x
is an n
-dimensional numerical array. Conversion follows the general C rules. Note that both NaN
and Inf
in the real and imaginary parts are both preserved under type conversion.
dcomplex
. First, we convert from an integer (the argument is an integer because no decimal is present):
--> dcomplex(200) ans = <dcomplex> - size: [1 1] 200 0i
In the next example, a double precision argument is passed in (the presence of a decimal without the f
suffix implies double precision).
--> dcomplex(400.0) ans = <dcomplex> - size: [1 1] 400 0i
In the next example, a complex argument is passed in.
--> dcomplex(3.0+4.0*i) ans = <dcomplex> - size: [1 1] 3+ 4i
In the next example, a string argument is passed in. The string argument is converted into an integer array corresponding to the ASCII values of each character.
--> dcomplex('h') ans = <dcomplex> - size: [1 1] 104 0i
In the next example, the NaN
argument is converted.
--> dcomplex(nan) ans = <dcomplex> - size: [1 1] nan 0i
In the last example, a cell-array is passed in. For cell-arrays and structure arrays, the result is an error.
--> dcomplex({4}) Error: Cannot convert cell-arrays to any other type.