Debian Codegraph @

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

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