实际上,我在Scilab的控制台上有一个很大的矩阵。在latex的TeXt文件中输入这个矩阵是非常繁琐的。我的目标是在文本文件中自动为这个矩阵编写latex代码。有人能帮我吗?[我在控制台中有像这个A=0.2 0.3 0.3;0.4 0.5 0.6;0.7 0.8 0.9这样的大矩阵]。(大的意思是行运行约30,列运行约6)。
发布于 2018-08-23 17:40:26
你的问题缺少关于输入矩阵的信息:实数,复数,整数值?你想要什么样的输出:浮点型,指数型?
由于您的问题相当简单且不稳定,下面是一个假设是实数矩阵的答案:
function display_as_pmatrix(A,fmt)
if ~exists('fmt') then // default format : 10-th wide exponential notation with 3 digit
fmt='%10.3e'
end
// writing a latex pmatrix
// & between each term
// \\ a the end of each row
// except on the last row
mprintf('\\begin{pmatrix}\n') // mprintf accept C-printf
for j=1:size(A,1)-1
mprintf(fmt,A(j,1).')
mprintf(' \& '+fmt,A(j,2:$).')
mprintf('\\\\\n')
end
j=size(A,1)
mprintf(fmt,A(j,1).')
mprintf(' \& '+fmt,A(j,2:$).')
mprintf('\n\\end{pmatrix}\n')
endfunction此函数的用法如下
-->display_as_pmatrix(A,'%10.3e')
\begin{pmatrix}
2.360e-01 & 8.837e-01 & 2.262e-02\\
4.076e-01 & 2.393e-01 & 8.311e-01\\
7.294e-01 & 9.087e-01 & 4.105e-01
\end{pmatrix}
-->display_as_pmatrix(A,'%5.2g')
\begin{pmatrix}
0.24 & 0.88 & 0.23\\
0.41 & 0.24 & 0.83\\
0.73 & 0.91 & 0.41
\end{pmatrix}发布于 2018-08-23 22:05:16
您可以简单地使用本机函数prettyprint
--> z = rand(4,4);
--> prettyprint(z)
ans =
${\begin{pmatrix}0.6733739&0.1899375&0.0403497&0.2514597\cr 0.6536
925&0.2583981&0.7400147&0.3843350\cr 0.1996896&0.0987874&0.6162660
&0.4396460\cr 0.6014125&0.0619903&0.6583583&0.6540737\cr \end{pmat
rix}}$ 结果有点凌乱,但您可以将其以最低版本复制并粘贴到TeX文件中。例如,我必须删除关键字pmatrix中的换行符
\documentclass{standalone}
\usepackage{amsmath}
\begin{document}
${\begin{pmatrix}0.6733739&0.1899375&0.0403497&0.2514597\cr 0.6536
925&0.2583981&0.7400147&0.3843350\cr 0.1996896&0.0987874&0.6162660
&0.4396460\cr 0.6014125&0.0619903&0.6583583&0.6540737\cr \end{pmatrix}}$
\end{document}输出:

如果您的矩阵超过10列,则需要在前同步码中添加\setcounter{MaxMatrixCols}{ncols},其中ncols大于列数。
https://stackoverflow.com/questions/51978392
复制相似问题