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

Version 1.7.0 (2,65 KB) von gwoo
Writes cell array content into a *.csv file.
116 Downloads
Aktualisiert 4. Nov 2019

Lizenz anzeigen

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!

Zitieren als

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. Abgerufen.

Kompatibilität der MATLAB-Version
Erstellt mit R2019b
Kompatibel mit allen Versionen
Plattform-Kompatibilität
Windows macOS Linux
Kategorien
Mehr zu Performance and Memory finden Sie in Help Center und MATLAB Answers
Tags Tags hinzufügen
Quellenangaben

Inspiriert: 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 Veröffentlicht Versionshinweise
1.7.0