Home > biosig > t200 > str2double.m

str2double

PURPOSE ^

% STR2DOUBLE converts strings into numeric values

SYNOPSIS ^

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

DESCRIPTION ^

% STR2DOUBLE converts strings into numeric values
%  [NUM, STATUS,STRARRAY] = STR2DOUBLE(STR) 
%  
%  STR2DOUBLE can replace STR2NUM, but avoids the insecure use of EVAL 
%  on unknown data [1]. 
%
%    STR can be the form '[+-]d[.]dd[[eE][+-]ddd]' 
%    d can be any of digit from 0 to 9, [] indicate optional elements
%    NUM is the corresponding numeric value. 
%       if the conversion fails, status is -1 and NUM is NaN.  
%    STATUS = 0: conversion was successful
%    STATUS = -1: couldnot convert string into numeric value
%    STRARRAY is a cell array of strings. 
%
%    Elements which are not defined or not valid return NaN and 
%        the STATUS becomes -1 
%    STR can be also a character array or a cell array of strings.   
%        Then, NUM and STATUS return matrices of appropriate size. 
%
%    STR can also contain multiple elements.
%    default row-delimiters are: 
%        NEWLINE, CARRIAGE RETURN and SEMICOLON i.e. ASCII 10, 13 and 59. 
%    default column-delimiters are: 
%        TAB, SPACE and COMMA i.e. ASCII 9, 32, and 44.
%    default decimal delimiter is '.' char(46), sometimes (e.g in 
%    Tab-delimited text files generated by Excel export in Europe)  
%    might used ',' as decimal delimiter.
%
%  [NUM, STATUS] = STR2DOUBLE(STR,CDELIM,RDELIM,DDELIM) 
%       CDELIM .. [OPTIONAL] user-specified column delimiter
%       RDELIM .. [OPTIONAL] user-specified row delimiter
%       DDELIM .. [OPTIONAL] user-specified decimal delimiter
%       CDELIM, RDELIM and DDELIM must contain only 
%       NULL, NEWLINE, CARRIAGE RETURN, SEMICOLON, COLON, SLASH, TAB, SPACE, COMMA, or ()[]{}  
%       i.e. ASCII 0,9,10,11,12,13,14,32,33,34,40,41,44,47,58,59,91,93,123,124,125 
%
%    Examples: 
%    str2double('-.1e-5')
%       ans = -1.0000e-006
%
%     str2double('.314e1, 44.44e-1, .7; -1e+1')
%    ans =
%        3.1400    4.4440    0.7000
%      -10.0000       NaN       NaN
%
%    line ='200,300,400,NaN,-inf,cd,yes,no,999,maybe,NaN';
%    [x,status]=str2double(line)
%    x =
%       200   300   400   NaN  -Inf   NaN   NaN   NaN   999   NaN   NaN
%    status =
%        0     0     0     0     0    -1    -1    -1     0    -1     0
%
% Reference(s): 
% [1] David A. Wheeler, Secure Programming for Linux and Unix HOWTO.
%    http://en.tldp.org/HOWTO/Secure-Programs-HOWTO/

CROSS-REFERENCE INFORMATION ^

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