No License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from

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



Sergey (view profile)


30 Sep 2008 (Updated )

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

| Watch this File

File Information

csvwriteFast( filename, values, format )

>> 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 );

Comment only

Contact us