str2num - Convert string to number

Syntax

x = str2num('str')
[x status] = str2num('str')

Description

x = str2num('str') converts the string str, which is an ASCII character representation of a numeric value, to numeric representation. str2num also converts string matrices to numeric matrices. If the input string does not represent a valid number or matrix, str2num(str) returns the empty matrix in x.

The input string can contain

[x status] = str2num('str') returns the status of the conversion in logical status, where status equals logical 1 (true) if the conversion succeeds, and logical 0 (false) otherwise. If the input string str does not represent a valid number or matrix, the MATLAB® software sets x to the empty matrix. If the conversions fails, status is set to 0.

Space characters can be significant. For instance, str2num('1+2i') and str2num('1 + 2i') produce x = 1+2i, while str2num('1 +2i') produces x = [1 2i]. You can avoid these problems by using the str2double function.

Examples

str2num('3.14159e0') is approximately π.

To convert a string matrix,

str2num(['1 2';'3 4'])

ans =

     1     2
     3     4

See Also

num2str, hex2num, sscanf, sparse, special characters

  


 © 1984-2008- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS