Code covered by the BSD License  

Highlights from

Be the first to rate this file! 8 Downloads (last 30 days) File Size: 1.58 KB File ID: #40157 Version: 1.3



Jacob (view profile)


04 Feb 2013 (Updated )

simple and elegant matlab function to quickly write large matrices to an ascii file.

| Watch this File

File Information

Writes large matrices to an ascii file. Format is up to user. Function automatically appends to file. It is many times (10-20X) faster than dlmwrite and almost as fast as using a mex file. Uses sprintf and fwrite (opposed to fprintf).

Example usage:

M = rand(1e5,3)*1000;
Elapsed time is 7.446049 seconds.
Elapsed time is 0.513611 seconds.

Required Products MATLAB
MATLAB release MATLAB 7.13 (R2011b)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (1)
07 Sep 2013 Jan Simon

Jan Simon (view profile)

Under Matlab 2011b this is 20% faster for your example data:

nCols = size(data, 2);
fid = fopen(filename, 'w');
Fmt = [repmat([Fmt, delimiter], 1, nCols-1), Fmt, char(10)];
fprintf(fid, Fmt, data');

The name "format" shadows a built-in function, therefore I'd prefer "Fmt" here.

Comment only
04 Feb 2013 1.2

added example usage in description

03 Sep 2013 1.3

fixed code comments so help command works

Contact us