MATLAB Function Reference Previous page   Next Page
csvread

Read comma-separated value file

Syntax

Description

M = csvread('filename') reads a comma-separated value formatted file, filename. The result is returned in M. The file can only contain numeric values.

M = csvread('filename', row, col) reads data from the comma-separated value formatted file starting at the specified row and column. The row and column arguments are zero based, so that row=0 and col=0 specify the first value in the file.

M = csvread('filename', row, col, range) reads only the range specified. Specify range using the notation [R1 C1 R2 C2] where (R1,C1) is the upper left corner of the data to be read and (R2,C2) is the lower right corner. You can also specify the range using spreadsheet notation, as in range = 'A1..B7'.

Remarks

csvread fills empty delimited fields with zero. Data files having lines that end with a nonspace delimiter, such as a semicolon, produce a result that has an additional last column of zeros.

csvread imports 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|j
-7j

Embedded white-space in a complex number is invalid and is regarded as a field delimiter.

Examples

Given the file csvlist.dat that contains the comma-separated values

To read the entire file, use

To read the matrix starting with zero-based row 2, column 0, and assign it to the variable m,

To read the matrix bounded by zero-based (2,0) and (3,3) and assign it to m,

See Also

csvwrite, dlmread, textscan, wk1read, file formats, importdata, uiimport


Previous page   csch csvwrite Next page

© 1994-2005 The MathWorks, Inc.