0001 function asciiWrite(mat, fileName, format)
0002
0003
0004
0005
0006
0007
0008 if nargin<1, selfdemo; return; end
0009 if nargin<2, fileName='asciiFile.txt'; end
0010 if nargin<3, format='%g'; end
0011
0012 fid = fopen(fileName, 'w');
0013 for i = 1:size(mat,1),
0014 fprintf(fid, [format, ' '], mat(i, :));
0015 fprintf(fid, '\n');
0016 end
0017 fclose(fid);
0018
0019
0020 function selfdemo
0021 x=magic(5);
0022 fileName=tempname;
0023 asciiWrite(x, fileName, '%d');
0024 fprintf('The content of %s is\n', fileName);
0025 type(fileName);