strtod
parse and convert literal numbers STRings TO Decimal numbers
Syntax
[d, tails] = strtod(str) [d, tails] = strtod(str, decimalseparator)
Arguments
- str
single component, vector, or matrix of strings.
- decimalseparator
the decimal separator chosen: "." (by default) or ",".
- d
scalar, vector, or matrix of decimal numbers.
- tails
a string or matrix of strings: remaining parts of
strafter the numerical heads (if any).
Description
[d, tails] = strtod(str) parses each string of
str and tries to interpret its content as a decimal
number:
- If it succeeds, at least for the heading part of
str(i), the corresponding decimal number is returned ind(i). If any, the trailing part ofstr(i)is ignored and returned intails(i); otherwise,tails(i)returns "". - Otherwise,
d(i)returns%nan, andtails(i)is the wholestr(i).
![]() |
|
Examples
s = ["123.556 abc " ".543" "#58B" "0x73 " "%inf" "-1.47e-71" "67,432.57" " 23,5" "-,57" "Inf" ] [num, trail] = strtod(s); num, "/"+trail+"/" // With "," as decimal separator: [num, trail] = strtod(s, ","); num, "/"+trail+"/"
See also
History
| バージョン | 記述 |
| 5.5.0 | Option decimalseparator introduced (SEP 97). |
| 5.4.1 | If str does not contain any numerical value,
d now returns Nan
instead of 0. |
| Report an issue | ||
| << strsubst | Strings | strtok >> |
