<< csv_read CSV read write files csv_textscan >>

CSV read write files >> CSV read write files > csv_stringtodouble

csv_stringtodouble

Convert a matrix of strings to a matrix of doubles.

Calling Sequence

r = csv_stringtodouble(strs)
r = csv_stringtodouble(strs,convertStrToNan)

Parameters

strs

a m-by-n matrix of strings.

convertStrToNan

a 1-by-1 matrix of booleans (default convertStrToNan=%t). If %t it converts no valid string to Nan. If %f a no valid string returns a error.

r

a m-by-n matrix of doubles.

Description

Convert a matrix of strings to a matrix of double.

This function is faster than evstr to convert a matrix convert a matrix of strings to a matrix of double.

The csv_stringtodouble converts any complex number as a whole into a complex numeric field, converting the real and imaginary parts to the specified numeric type.

Valid forms for a complex number are :

Form Example
±<real>±<imag>i|j 5.7-3.1i
±<imag>i|%i|j -7j

Examples

csv_stringtodouble("123.45e7")
csv_stringtodouble("123 + 45i")
csv_stringtodouble("123 + 45%i")
csv_stringtodouble("123 + 45*%i")
csv_stringtodouble("3.14159")
csv_stringtodouble(["2.71" "3.1415"])

mA = string(1:100);
r = csv_stringtodouble(mA)

r = csv_stringtodouble("2.6 + 3j")
r = csv_stringtodouble("2.6 + 3*%i")
r = csv_stringtodouble("2.6 + 3%i")

csv_stringtodouble("not a number")
csv_stringtodouble("not a number", %t)
csv_stringtodouble("not a number", %f)

In the following script, we compare the performances of the evstr and csv_stringtodouble functions. Typical values of t1/t2 are between 3 and 10.

n=10000;
x = string(1:n);
tic();evstr(x);t1=toc()
tic();csv_stringtodouble(x);t2=toc()
t1/t2

For large values of n, the previous script can fail because of a lack of memory, while csv_stringtodouble may succeed.

Author

Copyright (C) 2010-2011 - DIGITEO - Allan CORNET

Copyright (C) 2011 - DIGITEO - Michael Baudin

<< csv_read CSV read write files csv_textscan >>