forked from ipsorakis/GeneralNetworkTools
-
Notifications
You must be signed in to change notification settings - Fork 1
/
export_matrix_to_LaTeX.m
61 lines (48 loc) · 1.17 KB
/
export_matrix_to_LaTeX.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
function export_matrix_to_LaTeX(A,tablename,filename,integer_flag)
if ~exist('integer_flag','var')
integer_flag = false;
end
[rows cols] = size(A);
fid = fopen(filename,'w');
fprintf(fid,strcat('\mathbf{',tablename,'} = '));
fprintf(fid,'\\left[\\begin{array}{');
for j=1:cols
fprintf(fid,'c');
end
fprintf(fid,'}\n');
if integer_flag
for i=1:rows
for j=1:cols
fprintf(fid,'%d ',A(i,j));
if j<cols
fprintf(fid,'& ');
else
if i<rows
fprintf(fid,'\\\\\n');
else
fprintf(fid,'\\end{array} \\right]');
end
end
end
end
else
for i=1:rows
for j=1:cols
if A(i,j)~=0
fprintf(fid,'%.2f ',A(i,j));
else
fprintf(fid,'0');
end
if j<cols
fprintf(fid,'& ');
else
if i<rows
fprintf(fid,'\\\\\n');
else
fprintf(fid,'\\end{array} \\right]');
end
end
end
end
end
end