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