This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.


Write comma-separated value file




csvwrite(filename,M) writes matrix M into filename as comma-separated values. Specify filename as a character vector or string, for example, 'csvlist.dat' or "csvlist.dat".

csvwrite(filename,M,row,col) writes matrix M into filename starting at the specified row and column offset. The row and column arguments are zero based, so that row=0 and C=0 specify the first value in the file.


The following example creates a comma-separated value file from the matrix m.

m = [3 6 9 12 15; 5 10 15 20 25; ...
     7 14 21 28 35; 11 22 33 44 55];

type csvlist.dat


The next example writes the matrix to the file, starting at a column offset of 2.

type csvlist.dat



  • csvwrite terminates each line with a line feed character and no carriage return.

  • csvwrite writes a maximum of five significant digits. If you need greater precision, use dlmwrite with a precision argument.

  • csvwrite does not accept cell arrays for the input matrix M. To export a cell array that contains only numeric data, use cell2mat to convert the cell array to a numeric matrix before calling csvwrite. To export cell arrays with mixed alphabetic and numeric data, where each cell contains a single element, you can create an Excel® spreadsheet (if your system has Excel installed) using xlswrite. For all other cases, you must use low-level export functions to write your data. For more information, see Export Cell Array to Text File in the MATLAB® Data Import and Export documentation.

Introduced before R2006a

Was this topic helpful?