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