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

Versión 1.7.0 (2.65 KB) por gwoo
Writes cell array content into a *.csv file.
113 descargas
Actualizado 4 Nov 2019

Ver licencia

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!

Citar como

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

Compatibilidad con la versión de MATLAB
Se creó con R2019b
Compatible con cualquier versión
Compatibilidad con las plataformas
Windows macOS Linux
Categorías
Más información sobre Performance and Memory en Help Center y MATLAB Answers.
Etiquetas Añadir etiquetas
Agradecimientos

Inspiración para: 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!
Versión Publicado Notas de la versión
1.7.0