Skip to Main Content Skip to Search
Product Documentation

csvread - Read comma-separated value file

Syntax

M = csvread(filename)
M = csvread(filename, row, col)
M = csvread(filename, row, col, range)

Description

M = csvread(filename) reads a comma-separated value formatted file, filename. The filename input is a string enclosed in single quotes. 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'.

Tips

Examples

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

   02, 04, 06, 08, 10, 12
   03, 06, 09, 12, 15, 18
   05, 10, 15, 20, 25, 30
   07, 14, 21, 28, 35, 42
   11, 22, 33, 44, 55, 66

To read the entire file, use

csvread('csvlist.dat')

ans =

     2     4     6     8    10    12
     3     6     9    12    15    18
     5    10    15    20    25    30
     7    14    21    28    35    42
    11    22    33    44    55    66

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

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

m =

     5    10    15    20    25    30
     7    14    21    28    35    42
    11    22    33    44    55    66

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

m = csvread('csvlist.dat', 2, 0, [2,0,3,3])

m =

     5    10    15    20
     7    14    21    28

See Also

csvwrite | dlmread | importdata | textscan | uiimport

  


Free MATLAB Interactive Kit

Explore how to use MATLAB to make advancements in engineering and science.


Download free kit

Trials Available

Try the latest version of MATLAB and other MathWorks products.


Get trial software
 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS