csvReadRead comma-separated value fileCalling Sequence
M = csvRead(filename)
M = csvRead(filename, separator)
M = csvRead(filename, separator, decimal)
M = csvRead(filename, separator, decimal, conversion)
M = csvRead(filename, separator, decimal, conversion, substitute)
M = csvRead(filename, separator, decimal, conversion, substitute, regexpcomments, range)
M = csvRead(filename, separator, decimal, conversion, substitute, regexpcomments, range, header)
[M, comments] = csvRead(filename, separator, decimal, conversion, substitute, regexpcomments, range, header)
Argumentsfilenamea 1-by-1 matrix of strings, the file path.separatora 1-by-1 matrix of strings, the field separator used.decimala 1-by-1 matrix of strings, the decimal used.
If decimal is different of [] and conversion is set to string, the decimal conversion will be done.
conversiona 1-by-1 matrix of strings, the type of the output
M. Available values are "string" or "double" (by default).
Note that read_csv has "string" as default.
substitutea m-by-2 matrix of strings, a replacing map (default = [],
meaning no replacements). The first column
substitute(:,1) contains the searched strings and
the second column substitute(:,2) contains the
replace strings. Every occurence of a searched string in the file is
replaced.
regexpcommentsa string: a regexp to remove lines which match. (default:
[])
rangea 1-by-4 matrix of floating point integers, the range of rows
and columns which must be read (default range=[], meaning that all
the rows and columns). Specify range using the format [Row1 Column1 Row2 Column2]
where (R1,C1) is the upper left corner of the
data to be read and (R2,C2) is the lower right corner.
Note that the file has to be correctly formated. The range will be done in the memory on the parsed elements.headera 1-by-1 matrix of floating point integers, the number of lines to be ignored
at the beginning of the file.
Ma m-by-n matrix of strings or double.commentsa m-by-n matrix of strings matched by regexp.DescriptionGiven an ascii file with comma separated values delimited fields,
this function returns the corresponding Scilab matrix of strings or
doubles.
For example, the .csv data file may have been created by a
spreadsheet software using "Text and comma" format.
It might happen that the columns are separated by a non-comma
separator. In this case, use csvRead(filename, separator) for another
choice of separator.
The default value of the optional input arguments are defined by the
csvDefault function.
Any optional input argument equal to the empty matrix
[] is set to its default value.
When the input argument "conversion" is equal to "double", the
non-numeric fields within the .csv (e.g. strings) are converted into
NaN.
csvRead is able to handle both UTF-8 and ASCII text files.
ExamplesThe following script presents some basic uses of the
csvRead function.
The following script presents more practical uses of the
csvRead function.
The following script shows how to remove lines with regexp argument
of the csvRead function.
Empty field are managed by csvReadIn the following script, the file "filename" is read by blocks of
5000 rows. The algorithm stops when the number of rows actually read from
the file differ from 5000, i.e. when the end of the file has been
reached.
This produces:
Example with range
Example with header
See Also
csvWrite
History5.4.0
Function introduced. Based on the 'csv_readwrite' module. The only difference in the behavior compared to read_csv is that csvRead will try to convert value to double by default when read_csv will return value as string.
5.4.1
If decimal is different of [] and conversion is set to string, the decimal conversion will be done.
5.5
Addition of the "header" input argument, to ignore headers.