File Exchange

image thumbnail

CELLWRITE

version 1.0.0.0 (1.46 KB) by Francis Barnhart
Cellwrite writes mixed cell array data to a CSV file.

4 Downloads

Updated 06 Apr 2005

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.

Cite As

Francis Barnhart (2020). CELLWRITE (https://www.mathworks.com/matlabcentral/fileexchange/7363-cellwrite), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (15)

Renwen Lin

@Barry Williams:

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

MoKo

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

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!

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
fprintf(fid,'%s\n',file_line{:})

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.
thanks!

Kyle Archie

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

Barry Williams

Works well. Just what I needed!

MATLAB Release Compatibility
Created with R13
Compatible with any release
Platform Compatibility
Windows macOS Linux
Acknowledgements

Inspired: SynaptophysinROIDilation, Percent Area ROI