Cell Array to CSV-file [improved cell2csv.m]

Version (2.76 KB) by Jerry
Writes cell array content into a *.csv file.
Updated 10 Jul 2014

View License

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

now works with empty cells, numeric, char, string, row vector, and logical cells.
row vector such as [1 2 3] will be separated by two spaces, that is "1 2 3"
other types will be converted to the string "NA".
One array can contain all of them, but only one value per cell.
2x times faster than Sylvain's codes (8.8s vs. 17.2s):
tic;C={'te','tm';5,[1,2];true,{}};C=repmat(C,[10000,1]);cell2csv([datestr(now,'MMSS') '.csv'],C);toc;

credits go to Sylvain Fiedler:
modified and optimized from Sylvain Fiedler's codes at http://www.mathworks.com/matlabcentral/fileexchange/4400-cell-array-to-csv-file--cell2csv-m-

To get csv back to cell, use csv2cell(). There are a couple of that on fileexchange. I have packed them into a single library together with other useful routines. Feel free to check at http://www.mathworks.com/matlabcentral/fileexchange/47193-easy-matlab-and-shell-interaction-library--ez-m-

Cite As

Jerry (2024). Cell Array to CSV-file [improved cell2csv.m] (https://www.mathworks.com/matlabcentral/fileexchange/47055-cell-array-to-csv-file-improved-cell2csv-m), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2009a
Compatible with any release
Platform Compatibility
Windows macOS Linux
Find more on Cell Arrays in Help Center and MATLAB Answers

Inspired: fcell2csv - Fastest Cell Array to CSV-file

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Published Release Notes

link to my ez library

updated file description

replace repmat with subfunction

fixed a printing bug

made the parsing of arg more robust.

changed the title of this matlab page (nothing about codes itself)