annotate toolboxes/FullBNT-1.0.7/KPMtools/matprint.m @ 0:e9a9cd732c1e tip

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
rev   line source
wolffd@0 1 % MATPRINT - prints a matrix with specified format string
wolffd@0 2 %
wolffd@0 3 % Usage: matprint(a, fmt, fid)
wolffd@0 4 %
wolffd@0 5 % a - Matrix to be printed.
wolffd@0 6 % fmt - C style format string to use for each value.
wolffd@0 7 % fid - Optional file id.
wolffd@0 8 %
wolffd@0 9 % Eg. matprint(a,'%3.1f') will print each entry to 1 decimal place
wolffd@0 10
wolffd@0 11 % Peter Kovesi
wolffd@0 12 % School of Computer Science & Software Engineering
wolffd@0 13 % The University of Western Australia
wolffd@0 14 % pk @ csse uwa edu au
wolffd@0 15 % http://www.csse.uwa.edu.au/~pk
wolffd@0 16 %
wolffd@0 17 % March 2002
wolffd@0 18
wolffd@0 19 function matprint(a, fmt, fid)
wolffd@0 20
wolffd@0 21 if nargin < 3
wolffd@0 22 fid = 1;
wolffd@0 23 end
wolffd@0 24
wolffd@0 25 [rows,cols] = size(a);
wolffd@0 26
wolffd@0 27 % Construct a format string for each row of the matrix consisting of
wolffd@0 28 % 'cols' copies of the number formating specification
wolffd@0 29 fmtstr = [];
wolffd@0 30 for c = 1:cols
wolffd@0 31 fmtstr = [fmtstr, ' ', fmt];
wolffd@0 32 end
wolffd@0 33 fmtstr = [fmtstr '\n']; % Add a line feed
wolffd@0 34
wolffd@0 35 fprintf(fid, fmtstr, a'); % Print the transpose of the matrix because
wolffd@0 36 % fprintf runs down the columns of a matrix.