str2num
Returns a scalar, complex number or matrix, R, after converting the input s.
Syntax
R = str2num(s)
[R, returnval] = str2num(s)
Inputs
- s
- Type: String string | mat
Outputs
- R
- Type: scalar | complex number | matrix
- returnval (optional)
- Indicates the result of the conversion. A value of 1 indicates success and a value of 0 indicates failure.
Examples
String to scalar
conversion:
R = str2num('2.345e+5')
R = 234500
String to scalar conversion, with result of the
conversion:
[R, returnval] = str2num('2.345e+5')
R = 234500
returnval = 1
String to complex
conversion:
R = str2num('24 + 7i')
R = [Matrix] 1 x 1
24 + 7i
Matrix of strings to matrix of numbers
conversion:
R = str2num(['65', '66'; '88', '92'])
R = [Matrix] 2 x 1
6566
8892
Comments
Valid types for input s are strings or a matrix of strings. An optional output, returnval, can be used to determine result of the conversion. A value of 1 indicates the conversion was successful and a value of 0 otherwise.