Code covered by the BSD License  

Highlights from
Matrix to file

from Matrix to file by Nicolai Sten
Writes matrix to a file. Arguments: matrix and file-name

[]=matrix2file(A,name)
% Written by Nicolai Sten, 12th of June 2009 - on a train
% The matrix 'A' is written to the file 'name' - remember full file-name
% in the argument.
function []=matrix2file(A,name)
fid = fopen(name, 'wt');
dims=size(A);
for j=1:dims(1)
    k=0;
for i=1:dims(2)
fprintf(fid, '%12.8E\t', A(j,i));
k=k+1;
if k==dims(2);
    fprintf(fid, '\n');
end
end
end
fclose(fid);
%Ex: Matrix2file(A,'Cirkus.txt') writes the matrix A to the file Cirkus.txt
%    using tabulator seperation and exponential notation - uppercase e.

Contact us at files@mathworks.com