-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathGFRF2LaTeX.m
75 lines (68 loc) · 2.4 KB
/
GFRF2LaTeX.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
% Transforms the symbolic GFRFs to LaTeX format, for publishing purposes.
%
% written by: Renato Naville Watanabe
%
% GFRF2LaTeX(GFRF, size, filename, numberOfDigits)
%
%
% Inputs:
%
% GFRF: cell, contains all GFRFs.
%
% size: string, the specified math font size in LaTeX. For example: 'scriptscript' for
% \scriptscriptstyle size.
%
% filename: string, name of the file to store the LaTeX formatted GFRFs.
%
% numberOfDigits: integer, number of digits to represent the float numbers.
function GFRF2LaTeX(GFRF, size, filename, numberOfDigits)
%%
file = fopen(filename, 'w');
degree = length(GFRF);
sizeString = strcat(' \\',size,'style ');
D = digits;
digits(numberOfDigits);
outputString = '';
%%
outputString = strcat(outputString, '\\begin{align} \n');
for i = 1:degree
inputs = argnames(GFRF{i});
outputString = strcat(outputString, sizeString, ' H_', num2str(i), '(');
for j = 1:length(inputs)
if j == length(inputs)
outputString = strcat(outputString, strrep(char(inputs(j)), 'f', 'f_'));
else
outputString = strcat(outputString, strrep(char(inputs(j)), 'f','f_'), ',');
end
end
outputString = strcat(outputString,') =& ', sizeString);
%% GFRF
[num, den] = numden(GFRF{i});
%% numerator
numString = latex(vpa((num)));
numString = strrep(numString, '\','\\');
for j = 1:i
numString = strrep(numString, strcat('\\mathrm{f',num2str(j),'}'), strcat('f_',num2str(j)));
end
numString = strrep(numString, '\\mathrm{i}','j');
%% denominator
denString = latex(vpa((den)));
denString = strrep(denString, '\','\\');
for j = 1:i
denString = strrep(denString, strcat('\\mathrm{f',num2str(j),'}'), strcat('f_',num2str(j)));
end
denString = strrep(denString, '\\mathrm{i}','j');
%% GFRF
GFRFstring = strcat('\\frac{',numString,'}{',denString,'}');
outputString = strcat(outputString, GFRFstring);
%%
if i == degree
outputString = strcat(outputString, '\n');
else
outputString = strcat(outputString, '\\\\ \n');
end
end
outputString = strcat(outputString, '\\end{align}');
fprintf(file, outputString);
digits(D);
end