No BSD License  

Highlights from
csvwriteFast

Be the first to rate this file! 9 Downloads (last 30 days) File Size: 327 Bytes File ID: #21645

csvwriteFast

by

 

30 Sep 2008 (Updated )

fast writing of numerical data / matrices into a csv / text file

| Watch this File

File Information
Description

usage:
csvwriteFast( filename, values, format )

speed:
>> r = randn( 1e5, 2 );
>> tic, csvwrite( 'r.csv', r ), toc
Elapsed time is 3.945658 seconds.
>> tic, csvwriteFast( 'r.csv', r, '%f,%f' ), toc
Elapsed time is 0.302832 seconds.

another advantage is ability to specify the numerical format for each column separately

i've noticed that this approach is more significant on matrices with low number of columns. For example, it writes matrix with 10 columns merely 3 times faster than csvwrite, while in the example above (2 columns) this factor is over 13.

MATLAB release MATLAB 7.5 (R2007b)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (1)
21 Oct 2008 Thierry Dalon

This is the function:
function csvwriteFast( filename, values, format )
% values: numeric matrix
% format: C format, separate for each column of values.
% example:
% r=randn(1e5,3);
% csvwriteFast( 'r.csv', r, '%f,%f,%f' )

format = [ format, '\n' ];
fid = fopen( filename, 'w' );
fprintf( fid, format, values' );
fclose( fid );

Contact us