Converts the argument to a 64-bit floating point number. The syntax for its use is
y = double(x)
where x
is an n
-dimensional numerical array. Conversion follows the general C rules. Note that both NaN
and Inf
are both preserved under type conversion.
The following piece of code demonstrates several uses of double
. First, we convert from an integer (the argument is an integer because no decimal is present):
--> double(200) ans = <double> - size: [1 1] 200.000000000000
In the next example, a single precision argument is passed in (the presence of the f
suffix implies single precision).
--> double(400.0f) ans = <double> - size: [1 1] 400.000000000000
In the next example, a dcomplex argument is passed in. The result is the real part of the argument, and in this context, double
is equivalent to the function real
.
--> double(3.0+4.0*i) ans = <double> - size: [1 1] 3.000000000000000
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.
--> double('helo') ans = <double> - size: [1 4] Columns 1 to 2 104.000000000000 101.000000000000 Columns 3 to 4 108.000000000000 111.000000000000
In the last example, a cell-array is passed in. For cell-arrays and structure arrays, the result is an error.
--> double({4}) Error: Cannot convert cell-arrays to any other type.