wolffd@0: % MATPRINT - prints a matrix with specified format string wolffd@0: % wolffd@0: % Usage: matprint(a, fmt, fid) wolffd@0: % wolffd@0: % a - Matrix to be printed. wolffd@0: % fmt - C style format string to use for each value. wolffd@0: % fid - Optional file id. wolffd@0: % wolffd@0: % Eg. matprint(a,'%3.1f') will print each entry to 1 decimal place wolffd@0: wolffd@0: % Peter Kovesi wolffd@0: % School of Computer Science & Software Engineering wolffd@0: % The University of Western Australia wolffd@0: % pk @ csse uwa edu au wolffd@0: % http://www.csse.uwa.edu.au/~pk wolffd@0: % wolffd@0: % March 2002 wolffd@0: wolffd@0: function matprint(a, fmt, fid) wolffd@0: wolffd@0: if nargin < 3 wolffd@0: fid = 1; wolffd@0: end wolffd@0: wolffd@0: [rows,cols] = size(a); wolffd@0: wolffd@0: % Construct a format string for each row of the matrix consisting of wolffd@0: % 'cols' copies of the number formating specification wolffd@0: fmtstr = []; wolffd@0: for c = 1:cols wolffd@0: fmtstr = [fmtstr, ' ', fmt]; wolffd@0: end wolffd@0: fmtstr = [fmtstr '\n']; % Add a line feed wolffd@0: wolffd@0: fprintf(fid, fmtstr, a'); % Print the transpose of the matrix because wolffd@0: % fprintf runs down the columns of a matrix.