No BSD License  

Highlights from
cell2csv

4.75

4.8 | 8 ratings Rate this file 54 Downloads (last 30 days) File Size: 947 Bytes File ID: #7601

cell2csv

by Rob Kohr

 

05 May 2005 (Updated 09 May 2005)

Writes cell array content into a *.csv file.

| Watch this File

File Information
Description

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.

Acknowledgements
This submission has inspired the following:
csv2cell, Write Cell Array to Text File
MATLAB release MATLAB 7.0.1 (R14SP1)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (10)
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).

14 Feb 2006 Delong Liu

Great job.

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?

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

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)

Regards

10 Jul 2008 Xi Cheng

Wonderful, just what I need

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}']);
to:
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.

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.

29 Aug 2010 Ivan Brezani

works fine, thanks!

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

Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
data import Rob Kohr 22 Oct 2008 07:48:10
data export Rob Kohr 22 Oct 2008 07:48:10
cell Rob Kohr 22 Oct 2008 07:48:10
array Rob Kohr 22 Oct 2008 07:48:10
csv Rob Kohr 22 Oct 2008 07:48:10
data Rob Kohr 22 Oct 2008 07:48:11
utilties Rob Kohr 22 Oct 2008 07:48:11
export Rob Kohr 22 Oct 2008 07:48:11
import Rob Kohr 22 Oct 2008 07:48:11
csv Markus 14 Apr 2010 07:20:03
export Markus 14 Apr 2010 07:20:08
csv Gang 16 Aug 2011 22:25:49
cell Gang 16 Aug 2011 22:25:52
data Mairaj Zeb 18 Nov 2011 09:07:15

Contact us at files@mathworks.com