File Exchange

image thumbnail


version 1.0 (1.46 KB) by

Cellwrite writes mixed cell array data to a CSV file.

11 Ratings



View License

Editor's Note: This file was selected as MATLAB Central Pick of the Week

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.

Comments and Ratings (15)

Renwen Lin

Michael Neal

@Barry Williams:

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


MoKo (view profile)

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.

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 = '';
            contents=strrep(contents, ',' , '_' );

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

I change:
if isnumeric(contents)


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!

Kevin J. Delaney

Did just what I needed! Well done!

David Hsieh

David Hsieh

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

Ben Spivey

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

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

Thomas Heinz

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

Adam N

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

Kyle Archie

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

Barry Williams

Works well. Just what I needed!

MATLAB Release
MATLAB 6.5 (R13)

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

» Watch video