Documentation

This is machine translation

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

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

csvwrite

Write comma-separated value file

Syntax

csvwrite(filename,M)
csvwrite(filename,M,row,col)

Description

csvwrite(filename,M) writes matrix M into filename as comma-separated values. The filename input is a character vector specified as text enclosed in single quotes, for example, '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.

Examples

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];

csvwrite('csvlist.dat',m)
type csvlist.dat

3,6,9,12,15
5,10,15,20,25
7,14,21,28,35
11,22,33,44,55

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

csvwrite('csvlist.dat',m,0,2)
type csvlist.dat

,,3,6,9,12,15
,,5,10,15,20,25
,,7,14,21,28,35
,,11,22,33,44,55

More About

collapse all

Tips

  • 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?