Home > freetb4matlab > strings > str2double.m

str2double

PURPOSE ^

% Convert strings into numeric values.

SYNOPSIS ^

function [num, status, strarray] = str2double (s, cdelim, rdelim, ddelim)

DESCRIPTION ^

% -*- texinfo -*-
% @deftypefn {Function File} {[@var{num}, @var{status}, @var{strarray}] =} str2double (@var{str}, @var{cdelim}, @var{rdelim}, @var{ddelim})
% Convert strings into numeric values.
%
% @code{str2double} can replace @code{str2num}, but avoids the use of
% @code{eval} on unknown data.
%
% @var{str} can be the form @samp{[+-]d[.]dd[[eE][+-]ddd]} in which
% @samp{d} can be any of digit from 0 to 9, and @samp{[]} indicate
% optional elements.
%
% @var{num} is the corresponding numeric value.  If the conversion
% fails, status is -1 and @var{num} is NaN.
%
% @var{status} is 0 if the conversion was successful and -1 otherwise.
%
% @var{strarray} is a cell array of strings.
%
% Elements which are not defined or not valid return NaN and the
% @var{status} becomes -1.
%
% If @var{str} is a character array or a cell array of strings, then
% @var{num} and @var{status} return matrices of appropriate size. 
%
% @var{str} can also contain multiple elements separated by row and
% column delimiters (@var{cdelim} and @var{rdelim}).
% 
% The parameters @var{cdelim}, @var{rdelim}, and @var{ddelim} are
% optional column, row, and decimal delimiters.
%
% The default row-delimiters are newline, carriage return and semicolon
% (ASCII 10, 13 and 59).  The default column-delimiters are tab, space
% and comma (ASCII 9, 32, and 44).  The default decimal delimiter is
% @samp{.} (ASCII 46).
%
% @var{cdelim}, @var{rdelim}, and @var{ddelim} must contain only nul,
% newline, carriage return, semicolon, colon, slash, tab, space, comma,
% or @samp{[]@{@}} (ASCII 0, 9, 10, 11, 12, 13, 14, 32, 33, 34, 40,
% 41, 44, 47, 58, 59, 91, 93, 123, 124, 125).
%
% Examples:
%
% @example
% @group
% str2double ('-.1e-5')
% @result{} -1.0000e-006
%
% str2double ('.314e1, 44.44e-1, .7; -1e+1')
% @result{}
%    3.1400    4.4440    0.7000
%  -10.0000       NaN       NaN
%
% line = '200, 300, NaN, -inf, yes, no, 999, maybe, NaN';
% [x, status] = str2double (line)
% @result{} x =
%     200   300   NaN  -Inf   NaN   NaN   999   NaN   NaN
% @result{} status =
%       0     0     0     0    -1    -1     0    -1     0
% @end group
% @end example
% @seealso{str2num}
% @end deftypefn

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:
Generated on Fri 22-May-2009 15:13:00 by m2html © 2003