str2num
Convert character array to numeric array.
📝Syntax
x = str2num(s)
[x, ok] = str2num(s)
📥Input Arguments
Parameter Description
s a character vector or string scalar holding a numeric expression.
📤Output Arguments
Parameter Description
x the numeric result, or [] when the text cannot be evaluated to a number.
ok a logical: true when the conversion succeeded.
📄Description

x = str2num(s) converts the character array s to a numeric array by evaluating it.

Because str2num evaluates its input, prefer str2double for simple scalar conversions.

💡Examples
x = str2num('[1 2 3]')
[y, ok] = str2num('4 5; 6 7')
🔗See Also
str2doublenum2str
🕔Version History
Version Description
2.0.0 initial version
Edit this page on GitHub