-
Notifications
You must be signed in to change notification settings - Fork 0
/
tex.m
31 lines (28 loc) · 851 Bytes
/
tex.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
## tex_out by Jonathan Shea
## This software is released by the author to the public domain
## For more information see http://jonshea.com/copyright.html
## tex_out takes a matrix, var, and a string, name, and outputs the matrix
## to a texfile "name.tex" which is suitable to include in a LaTeX file with
## the command \input{name.tex}
function tex(var, name)
if(narin == 1)
name = var
endif
[rows, columns] = size(var);
fid = fopen(strcat(name, ".tex"), "wt", "native");
fprintf(fid, "\\begin{array}{");
for i = 1:columns
fprintf(fid, "c");
endfor
fprintf(fid, "}\n");
fmt = fmt0 = "\\mathtt{%#0.4g} ";
if (columns > 1)
for i = 2:columns
fmt = strcat(fmt, "& ", fmt0);
endfor
endif
fmt = strcat(fmt, "\\\\ \n");
fprintf(fid, fmt, var.');
fprintf(fid, "\\end{array}");
fclose(fid);
endfunction