-
Notifications
You must be signed in to change notification settings - Fork 5
/
matrix2tex.m
53 lines (43 loc) · 1.01 KB
/
matrix2tex.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
function matrix2tex(M,n)
% matrix2tex(M,n)
% ---------------
%
% Converts a Matlab matrix to a latex file using bordermatrix with all
% columns labeled.
%
% CALLS
% -----
%
% Kim Batselier, 2012-05-14
[p q] = size(M);
d = sum(fite(q,n));
openingstring = ['\bordermatrix{\text{}'];
monomial = '&1';
for i = 2:q
exponent = fite(i,n);
monomial = [monomial '&'];
for j = 1:n
if exponent(j)
if exponent(j)==1
monomial = [monomial 'x_' num2str(j)];
else
monomial = [monomial 'x_' num2str(j) '^' num2str(exponent(j))];
end
end
end
end
openingstring = [openingstring monomial '\cr'];
fid = fopen('matrix.txt','w');
fprintf(fid,'%s\n',openingstring);
numberstring =[];
for i = 1 : p
numberstring = [];
for j = 1:q
numberstring = [numberstring '&' num2str(M(i,j))];
end
numberstring = [numberstring '\cr'];
fprintf(fid,'%s\n',numberstring);
end
fprintf(fid,'%s\n\r','}');
fclose(fid);
end