convert Matlab array to Latex

조회 수: 29 (최근 30일)
Del
Del 2013년 6월 18일
답변: Daksh 2023년 2월 2일
I have an array of cells which I want to convert into a latex table.
I know for a simple array I can use the following command:
A = [1 2 3; 4 5 6; 7 8 9];
latex_table = latex(sym(A))
Which will create
latex_table =
\left(\begin{array}{ccc} 1 & 2 & 3\\ 4 & 5 & 6\\ 7 & 8 & 9 \end{array}\right)
However, if I have something like this
B = ['Hello World' '2' '3'; 'yes' 'a' '6'; 'yes' '8' 'john']
How can I create a latex table from the matrix B?

답변 (1개)

Daksh
Daksh 2023년 2월 2일
You can use the MATLAB latex() method to convert the MATLAB Array into latex table as follows:
B=["Hello" "2" "3"; "yes" "5" "6"; "Sam" "8" "John"];
latex_table = latex(sym(B))
latex_table = '\left(\begin{array}{ccc} \mathrm{Hello} & 2 & 3\\ \mathrm{yes} & 5 & 6\\ \mathrm{Sam} & 8 & \mathrm{John} \end{array}\right)'
If you intend to store "Hello World" inside the 1st element of the MATLAB array, it will yield an error while creating Latex table as it doesn't allow the same. For that, you can use the str2sym() method as follows:
B=[str2sym("Hello world") "2" "3"; "yes" "5" "6"; "Sam" "8" "John"];
latex_table = latex(sym(B))
latex_table = '\left(\begin{array}{ccc} \mathrm{Helloworld} & 2 & 3\\ \mathrm{yes} & 5 & 6\\ \mathrm{Sam} & 8 & \mathrm{John} \end{array}\right)'
Hope this helps!

카테고리

Help CenterFile Exchange에서 LaTeX에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by