Code covered by the BSD License  

Highlights from
CELLWRITE

4.9

4.9 | 10 ratings Rate this file 11 Downloads (last 30 days) File Size: 1.46 KB File ID: #7363

CELLWRITE

by Francis Barnhart

 

05 Apr 2005 (Updated 06 Apr 2005)

Cellwrite writes mixed cell array data to a CSV file.

| Watch this File

File Information
Description

This function implements the basic functionallity of csvwrite but operates on cell arrays of mixed data (numeric and string) instead of arrays of numeric data.

CELLWRITE(FILENAME, C) writes the cell array C to FILENAME as comma separated values.

Performance tests on 1000 by 100 matrices of random numeric data show performance nearly identical to CSVWRITE.

MATLAB release MATLAB 6.5 (R13)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (14)
28 Jul 2006 Barry Williams

Works well. Just what I needed!

31 Aug 2006 Kyle Archie

no idea why this is isn't already a standard function. Thanks!

06 Feb 2007 Adam N

excellent! would be better if we could choose the delimiter i.e. tab, comma, semicolon, etc.
thanks!

08 Feb 2007 Thomas Heinz

yes, why isn't it a standard function?! Thanks!

11 Aug 2008 Ben Spivey

I have noticed that Matlab 7.5 needs a revision to cellwrite to work with cells:

fprintf(fid,'%s\n',file_line) should be
fprintf(fid,'%s\n',file_line{:})

11 Aug 2008 Ben Spivey

the {:} addition is needed when the cell array has one layer of embedded cell arrays - the format that textscan provides.

10 Sep 2008 David Hsieh

This was terrific. I don't see why this WASN'T included with MATLAB originally, but it should definitely come standard.

10 Sep 2008 David Hsieh  
10 Apr 2009 Kevin J. Delaney

Did just what I needed! Well done!

11 Jul 2009 Geoffrey Akien

I've been using this for a while now and its great but...one of the tests for changing numbers into text needs adjusting for logicals...

I change:
if isnumeric(contents)

into

if isnumeric(contents) || islogical(contents)

Because the logical class is not including in isnumeric (helpfully). It may add a small speed hit, but it increases the robustness a little.

Thanks for the program though!

13 Aug 2009 Guillaume Majeau-Bettez

Thanks so much, this is a lifesaver. Great when working on Linux OS. I added one line to replace any comma already existing in the texts by '_' before writing contents. Important if you have chemical names in there.
...
elseif isempty(contents)
            contents = '';
        else
            contents=strrep(contents, ',' , '_' );
       end

06 May 2011 Richard Moore

Works great! I changed the 'w' to an 'a' in the fopen statement so that I could add lines to the csv in successive calls in a loop.

21 Aug 2011 Mohammad  
12 May 2012 Michael Neal

@Barry Williams:

I am just curious what made you give it four stars.

Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
data import Francis Barnhart 22 Oct 2008 07:45:03
data export Francis Barnhart 22 Oct 2008 07:45:03
cell array Francis Barnhart 22 Oct 2008 07:45:03
csv Francis Barnhart 22 Oct 2008 07:45:03
output Francis Barnhart 22 Oct 2008 07:45:03
mixed Francis Barnhart 22 Oct 2008 07:45:03
data Francis Barnhart 22 Oct 2008 07:45:03
csvwrite Francis Barnhart 22 Oct 2008 07:45:03
cell array Pia 02 May 2010 14:29:17

Contact us at files@mathworks.com