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).
M = rand(1e5,3)*1000;
Elapsed time is 7.446049 seconds.
Elapsed time is 0.513611 seconds.
It's a few years late, but after changing your code to include the carriage return like mine (personal preference), they appear to run at approximately the same speed for me. Your version is, however, done in a few less lines. Thanks for the suggestion.
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.
fixed code comments so help command works
added example usage in description
Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.