Code covered by the BSD License  

Highlights from
write_ascii

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

write_ascii

by

 

04 Feb 2013 (Updated )

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

| Watch this File

File Information
Description

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;
tic;dlmwrite('test.txt',M,'delimiter','\t','precision','%9.3f');toc;
tic;write_ascii('test2.txt',M,'\t','%9.3f');toc;
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

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');
fclose(fid);

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

Updates
04 Feb 2013

added example usage in description

03 Sep 2013

fixed code comments so help command works

Contact us