How can I create a LaTeX table from a MATLAB array?

35 ビュー (過去 30 日間)
MathWorks Support Team
MathWorks Support Team 2009 年 6 月 27 日
コメント済み: Walter Roberson 2020 年 11 月 13 日
I would like to create a LaTeX table from a MATLAB array.

採用された回答

MathWorks Support Team
MathWorks Support Team 2009 年 6 月 27 日
If you have the Symbolic Math Toolbox, you can use the LATEX function in conjunction with SYM to create a LaTeX table to represent MATLAB data in a table format. For example:
A = [1 2 3; 4 5 6; 7 8 9];
latex_table = latex(sym(A))
The resulting value in latex_table will be:
\left [\begin {array}{ccc} 1&2&3\\\noalign{\medskip}4&5&6\\\noalign{\medskip}7&8&9\end {array}\right ]
This string can then be pasted into any LaTex document.
  3 件のコメント
Frieder Wittmann
Frieder Wittmann 2020 年 11 月 13 日
This is a nice solution. Unfortunately it does not work well with doubles, as sym() will turn the doubles into fractions.
Walter Roberson
Walter Roberson 2020 年 11 月 13 日
Frieder Wittmann, it does work:
%default with the sympref not set
>> latex(sym(rand))
ans =
'\frac{4411405500742427}{9007199254740992}'
%set it
>> sympref('FloatingPointOutput',1)
ans =
logical
0
%and experiment again
>> latex(sym(rand))
ans =
'0.4456'

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeConversion Between Symbolic and Numeric についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by