Name

read_csv — Read comma-separated value file

Calling Sequence

M = csv_read(filename [, separator [,decimal [,conversion]]])

Parameters

filename

a character string. The file path.

separator

a character string. Field separator used, default value is ","

decimal

a character string. Field decimal used, default value is "."

conversion

a character string. Field conversion used ("string" or "double"), default value is "string"

M

a matrix of strings or double.

Description

Given an ascii file with delimited fields, for instance created by a spreadsheet using "Text and comma" format, csv_read(filename) returns the corresponding Scilab matrix of strings. Use csv_read(filename, separator) for another choice of separator.

with parameter "conversion" equals to "double" strings are converted as NaN.

Examples

// create a file with some data separated with tab    
A = 1:50;
csv_write(A, TMPDIR + '/foo.csv', ascii(9), '.')
mgetl(TMPDIR + '/foo.csv')

// read csv file
B = csv_read(TMPDIR + '/foo.csv',ascii(9))

// as double
C = csv_read(TMPDIR + '/foo.csv',ascii(9), '.', 'double')

// compares original data and result
and(A == C)

See Also

csv_write

Authors

Allan CORNET