Convert a string to a real or complex number.
The string must be in one of the following formats where a and b are real numbers and the complex unit is
- a + bi
- a + b*i
- a + i*b
- bi + a
- b*i + a
- i*b + a
If present, a and/or b are of the form [+-]d[,.]d[[eE][+-]d] where the brackets indicate optional arguments and
'd'indicates zero or more digits. The special input values
NAare also accepted.
s may be a character string, character matrix, or cell array. For character arrays the conversion is repeated for every row, and a double or complex array is returned. Empty rows in s are deleted and not returned in the numeric array. For cell arrays each character string element is processed and a double or complex array of the same dimensions as s is returned.
For unconvertible scalar or character string input
str2doublereturns a NaN. Similarly, for character array input
str2doublereturns a NaN for any row of s that could not be converted. For a cell array,
str2doublereturns a NaN for any element of s for which conversion fails. Note that numeric elements in a mixed string/numeric cell array are not strings and the conversion will fail for these elements and return NaN.
str2num, and it avoids the security risk of using
evalon unknown data.
See also: str2num.