-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconvert2latex.m
More file actions
32 lines (27 loc) · 769 Bytes
/
convert2latex.m
File metadata and controls
32 lines (27 loc) · 769 Bytes
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
%=================README======================
%Author: Junming Huang
%Contact: [email protected]
%This is a function to convert the matlab matrix
%to latex
%=================EXAMPLE=====================
%I have a matrix a = [1 0 0; 0 1 0; 0 0 1];
%convert2latex(a) then this function can convert
%your matrix to latex, you can copy and paste to
%your latex project file.
function convert2latex(matrix)
[rows cols] = size(matrix);
str = [inputname(1),' = \\begin{pmatrix}'];
format shortEng;
for i = 1 : rows
for j = 1 : cols
str = [str, num2str(matrix(i,j))];
if j == cols
str = [str, '\\','\\'];
else
str = [str, '&'];
end
end
end
str = [str, '\\end{pmatrix}', char(13,10)'];
fprintf(str);
end