Debian Codegraph @

contrib/ms-sbvar/TZcode/MatlabFiles/fn_fprintmatrix.m

raw
1 function fn_fprintmatrix(fid, M, nrows, ncols, indxFloat)
2 % Prints the matrix to an ascii file indexed by fid.
3 %
4 % Inputs:
5 % fid: Ascii file id. Example: fid = fopen('outdatainp_3s_stv_tvms6lags.prn','a');
6 % M: The matrix to be written to the file.
7 % nrows: Number of rows of M.
8 % ncols: Number of columns of M.
9 % indxFloat: 1 if double;
10 % 2 if single;
11 % 3 if only 3 significant digits
12 % 0 if integer.
13 %
14 % Copyright (C) 1997-2012 Tao Zha
15 %
16 % This free software: you can redistribute it and/or modify
17 % it under the terms of the GNU General Public License as published by
18 % the Free Software Foundation, either version 3 of the License, or
19 % (at your option) any later version.
20 %
21 % It is distributed in the hope that it will be useful,
22 % but WITHOUT ANY WARRANTY; without even the implied warranty of
23 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 % GNU General Public License for more details.
25 %
26 % If you did not received a copy of the GNU General Public License
27 % with this software, see <http://www.gnu.org/licenses/>.
28 %
29
30 %
31 if nrows~=size(M,1)
32 error('fn_fprintmatrix(): Make sure the row number supplied match that of the matrix');
33 end
34 if ncols~=size(M,2)
35 error('fn_fprintmatrix(): Make sure the column number supplied match that of the matrix');
36 end
37 for ki=1:nrows
38 for kj=1:ncols
39 if (indxFloat == 1)
40 fprintf(fid,' %.16e ',M((kj-1)*nrows+ki));
41 elseif (indxFloat == 2)
42 fprintf(fid,' %.8e ',M((kj-1)*nrows+ki));
43 elseif (indxFloat == 3)
44 fprintf(fid,' %.3e ',M((kj-1)*nrows+ki));
45 else
46 fprintf(fid,' %d ',M((kj-1)*nrows+ki));
47 end
48 if (kj==ncols)
49 fprintf(fid,'\n');
50 end
51 end
52 if (ki==nrows)
53 fprintf(fid,'\n\n');
54 end
55 end