MATLAB: How to create a LaTeX table from a MATLAB array

arraylatexmatrixSymbolic Math Toolboxtable

I would like to create a LaTeX table from a MATLAB array.

Best Answer

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.