No BSD License  

Highlights from

4.7 | 15 ratings Rate this file 52 Downloads (last 30 days) File Size: 947 Bytes File ID: #7601 Version: 1.0



Rob Kohr (view profile)


05 May 2005 (Updated )

Writes cell array content into a *.csv file.

| Watch this File

File Information

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.


This file inspired Flotation Kinetics Equation Fitting, Rosin Rammler Diagram Plotting Tool, Spm Neuro Synth Scraper, Csv2cell, and Write Cell Array To Text File.

MATLAB release MATLAB 7.0.1 (R14SP1)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (19)
11 Nov 2015 Kelly Kyriakou

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

24 Jun 2014 Jerry

Jerry (view profile)

See my improved version

Comment only
04 Nov 2013 Pawel Lachowicz

Exceeding my expectations. Great job.

24 Sep 2013 Pearl

Pearl (view profile)

06 Jul 2013 kb

kb (view profile)

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

04 Feb 2013 Jose Antonio

When the cell is logical doesn't work

17 Jan 2013 João Neves


30 Oct 2012 Franck Dernoncourt

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

31 Jul 2012 geieraffe

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

This script would be perfect.

Comment only
13 Apr 2011 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

Comment only
29 Aug 2010 Ivan Brezani

works fine, thanks!

20 Apr 2010 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.

Comment only
08 Sep 2008 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.

10 Jul 2008 Xi Cheng

Wonderful, just what I need

30 May 2008 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)


09 Nov 2007 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

17 Aug 2006 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?

14 Feb 2006 Delong Liu

Great job.

02 Sep 2005 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).

Contact us