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

版本 1.7.0 (2.7 KB) 作者: gwoo
Writes cell array content into a *.csv file.
116.0 次下载
更新时间 2019/11/4

查看许可证

First off, this an improvement on the code found here:
https://www.mathworks.com/matlabcentral/fileexchange/47055-cell-array-to-csv-file-improved-cell2csv-m

Credits to the original and previous authors for their work that this was built on.

This updated function:
- Improves performance when saving over network drives DRASTICALLY (by removing loop)
- Occasionally improves performance over local drive compared to previous cell2csv.m
- Improved performance over built-in writecell()
- Adds ability to set access permissions to output csv file (write, append, etc)
- Adds ability to set floating point precision (old cell2csv would typically limit at %.4f, and writecell is always %.15f)

Here are some timings I recorded on my computer:
% Input
>> x = [{'This', 'is', 'a', 'cell', 'time', 'test.'}; num2cell([(1:50000)', rand(50000,5)])];

On network:
% Compare to writecell
>> tic; cell2csv('new_cell2csv.csv', x, '%.15f'); toc
Elapsed time is 20.277467 seconds.
>> tic; writecell(x, 'writecell.csv'); toc
Elapsed time is 20.393940 seconds.

% Compare to old cell2csv
>> tic; cell2csv('new_cell2csv.csv', x); toc
Elapsed time is 19.339022 seconds.
>> tic; cell2csv('old_cell2csv.csv', x); toc
Elapsed time is 123.579863 seconds.

On local drive:
% Compare to writecell
>> tic; cell2csv('new_cell2csv.csv', x, '%.15f'); toc
Elapsed time is 18.165537 seconds.
>> tic; writecell(x, 'writecell.csv'); toc
Elapsed time is 21.017945 seconds.

% Compare to old cell2csv
>> tic; cell2csv('new_cell2csv.csv', x); toc
Elapsed time is 17.986039 seconds.
>> tic; cell2csv('old_cell2csv.csv', x); toc
Elapsed time is 14.386261 seconds.

Overall, it's a win!

引用格式

gwoo (2024). Faster Cell Array to CSV-file [more improved cell2csv.m] (https://www.mathworks.com/matlabcentral/fileexchange/73240-faster-cell-array-to-csv-file-more-improved-cell2csv-m), MATLAB Central File Exchange. 检索来源 .

MATLAB 版本兼容性
创建方式 R2019b
兼容任何版本
平台兼容性
Windows macOS Linux
类别
Help CenterMATLAB Answers 中查找有关 Performance and Memory 的更多信息
标签 添加标签

Community Treasure Hunt

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

Start Hunting!
版本 已发布 发行说明
1.7.0