File Exchange

image thumbnail


version 1.0 (947 Bytes) by

Writes cell array content into a *.csv file.

18 Ratings



No License

This function writes a cell array into a CSV-file.
It works with empty cells, numeric cells, char cells, and string cells. One array can contain all of them.

CSV-files can then be read by Excel, so you don't need DDE or ActiveX.

Written by Sylvain Fiedler. I just fixed the delimiter mistake.

Comments and Ratings (22)

Works great! I use this to write headers to CSV before using dlmwrite(....'-append')


Such a nice idea that is totally ruined by the use of |eval|. Why do beginners think that |eval| is a solution to anything?

For a much better alternative that does not use |eval|, see these FEX submissions:


For an explanation of why using |eval| is a bad way to code (no matter how much beginners love it):

Hopefully no beginners download this and learn to use |eval| for trivial code.

This is perfect. How I could add a row with headers?

Exceeding my expectations. Great job.


Pearl (view profile)


kb (view profile)

Thanks, it's useful. Numbers conversion is limited to 4 decimals tho. I added a decimals number option!e5gHEZBL!VXEmHX8hqxvwK0ZvrtW1qldtu7dk2KuR7L_DAKQyt5Y

Jose Antonio

When the cell is logical doesn't work

João Neves


works great (MATLAB 2012a, <1305983x3 cell>)


Is there an option to do this with "apped" like in DLMWRITE()?

This script would be perfect.

Murat Ates

xlswrite works much faster as Tim pointed. Only thing is I could not make it produce comma delimited cvs. I passed the 65536 row limit with Excel 2010. I found in some places they use xlFormat = 6 instead of 24 but both of them produces tab delimited csv.

“.csv”: FileFormatNum = 6
“.txt”: FileFormatNum = -4158
“.prn”: FileFormatNum = 36

Ivan Brezani

works fine, thanks!

Tim Sharp

For up to 65536 rows and 256 columns (or I assume more in Excel 2007 though I haven't tested), you can write to a csv file super-quick using a modified version of xlswrite. Simply add the enumeration xlFormat = 24 for when ext is csv in the switch-case around line 230 and you simply need to give xlswrite a filename that ends in csv.

Daniel Everson

This function is great. However, it seems that using "eval" on line 28 is unnecessary. By changing:
var = eval(['cellArray{z,s}']);
var = cellArray{z,s};
you get a significant increase in preformance. 16.5 seconds -> .45 seconds in the example I tested for a large cell.

Xi Cheng

Wonderful, just what I need

Sergey Bondarchuk

Thanks, it's useful function.
However, there is a little bug if the cell contains logical values because
isnumeric( logical(1) ) returns 0.
The line 26 should be replaced by:
if isnumeric(var) || islogical(var)


Jalal A

Dude, I love you. I'm learning matlab trial by error. So far ok, al the difficult tasks of parsing I can do. Its the simple stuff like export to txt or csv from cell arrays that stump me :P Thanks for posting

Matt Hoffman

Great function. Only problem is that MATLAB's csvread requires .csv files to be entirely numeric--any chance of a csv2cell in the future, which can read in text data as well?

Delong Liu

Great job.

Paras Jethwani

This utility is quite helpful since I do not know of any way to export MATLAB data to a CSV file which is a very basic requirement.

Nevertheless, this file must also provide support for exporting simple arrays (minor changes required).

MATLAB Release
MATLAB 7.0.1 (R14SP1)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video