Documentation

This is machine translation

Translated by Microsoft
Mouse over text to see original. Click the button below to return to the English verison of the page.

我们为许可用户提供了部分翻译好的中文文档。您只需登录便可查阅这些文档

csvread

Read comma-separated value (CSV) file

Syntax

  • M = csvread(filename)
    example
  • M = csvread(filename,R1,C1)
    example
  • M = csvread(filename,R1,C1,[R1 C1 R2 C2])
    example

Description

example

M = csvread(filename) reads a comma-separated value (CSV) formatted file into array M. The file must contain only numeric values.

example

M = csvread(filename,R1,C1) reads data from the file starting at row offset R1 and column offset C1. For example, the offsets R1=0, C1=0 specify the first value in the file.

example

M = csvread(filename,R1,C1,[R1 C1 R2 C2]) reads only the range bounded by row offsets R1 and R2 and column offsets C1 and C2. Another way to define the range is to use spreadsheet notation, such as 'A1..B7' instead of [0 0 6 1].

Examples

collapse all

Create a file named csvlist.dat that contains comma-separated values.

   02, 04, 06, 08
   03, 06, 09, 12
   05, 10, 15, 20
   07, 14, 21, 28
  

Read the numeric values in the file.

filename = 'csvlist.dat';
M = csvread(filename)
M =

     2     4     6     8
     3     6     9    12
     5    10    15    20
     7    14    21    28

Read the matrix starting two rows below the first row from the file described in the previous example.

M = csvread('csvlist.dat',2,0)
M =

     5    10    15    20
     7    14    21    28

Read the matrix bounded by row offsets 1 and 2 and column offsets 0 and 2 from the file described in the first example.

M = csvread('csvlist.dat',1,0,[1,0,2,2])
M =

     3     6     9
     5    10    15

Input Arguments

collapse all

File name, specified as a character vector.

Example: 'myFile.dat'

Data Types: char

Starting row offset, specified as a nonnegative integer. The first row has an offset of 0.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Starting column offset, specified as a nonnegative integer. The first column has an offset of 0.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Ending row offset, specified as a nonnegative integer. The first row has an offset of 0.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Ending column offset, specified as a nonnegative integer. The first column has an offset of 0.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

More About

collapse all

Tips

  • Skip header rows or columns by specifying row and column offsets. All values in the file other than headers must be numeric.

Algorithms

csvread fills empty delimited fields with zero. When the csvread function reads data files with lines that end with a nonspace delimiter, such as a semicolon, it returns a matrix, M, 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. The table shows valid forms for a complex number.

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.

Introduced before R2006a


Was this topic helpful?