Wiki source for MatrixToLatex


Show raw source

=====Matrix to Latex=====

Konvertiert [[Matlab]]- und [[Octave]]-Matrizen oder -Vektoren in Latex-Code


====Beispiele====

==Beispiel 1==

%%(matlab)
A = diag(ones(5,1))
at2latex(A, 0)
%%

{{lf code="A = \begin{pmatrix} 1 & 0 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 0 & 1 \end{pmatrix}"}}


==Beispiel 2==

%%(matlab)
B = rand(5,6)
mat2latex(B, 3)
%%

{{lf code="B = \begin{pmatrix} 0.181 & 0.486 & 0.405 & 0.569 & 0.752 & 0.693 \\ 0.593 & 0.913 & 0.966 & 0.079 & 0.328 & 0.627 \\ 0.488 & 0.132 & 0.186 & 0.062 & 0.460 & 0.116 \\ 0.246 & 0.309 & 0.757 & 0.630 & 0.460 & 0.057 \\ 0.943 & 0.416 & 0.947 & 0.200 & 0.334 & 0.432 \end{pmatrix}"}}


==Beispiel 3==

%%(matlab)
v = rand(5,1) % Vector v
mat2latex(v, 2)
%%

{{lf code="\vec v = \begin{pmatrix} 0.31 \\ 0.41 \\ 0.73 \\ 0.38 \\ 0.33 \end{pmatrix}"}}



====Script====

Script für [[Octave]] und [[Matlab]] zum formatiren von Matrizen nach [[LaTeX]].
%%(matlab)
function s = mat2latex(A,dg)

s = '\begin{pmatrix} ';

[M,N] = size(A);

for m=1:M
for n=1:N
s = strcat(s, sprintf([' %0.' num2str(dg) 'f'], A(m,n)) );
if (n~=N)
s = strcat(s,' & ');
end
end
if (m~=M)
s = strcat(s,' \\ ');
end
end

s = strcat(s,' \end{pmatrix}');
%%



----
Siehe auch {{backlinks}}
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki