Debian Codegraph @

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

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