convert Matlab array to Latex
77 views (last 30 days)
Show older comments
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?
0 Comments
Answers (1)
Daksh
on 2 Feb 2023
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))
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))
Hope this helps!
0 Comments
See Also
Categories
Find more on LaTeX in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!