Convert the string (or character array) s to a number (or an array).
Examples:
str2num ("3.141596") ⇒ 3.141596 str2num (["1, 2, 3"; "4, 5, 6"]) ⇒ 1 2 3 4 5 6
The optional second output, state, is logically true when the conversion is successful. If the conversion fails the numeric output, x, is empty and state is false.
Caution: As str2num
uses the eval
function to do the
conversion, str2num
will execute any code contained in the string
s. Use str2double
for a safer and faster conversion.
For cell array of strings use str2double
.
See also: str2double, eval.
Package: octave