[Tex/LaTex] Converting Matlab arrays to LaTeX compatible Code

MATLABmiktextexmaker

I was looking for ways to convert some MATLAB 2D arrays directly to LaTeX executable code that prints it nicely. While searching I came across this answer

Including a Matlab table in document

The savetable command works for me but the problem is that the matrix is too large to even include in a landscape mode.

There are two solutions I see to this:

  1. Make the LaTeX understand the size and split wherever necessary to include all in a readable way.
  2. This is in particular my case — the matrix can still be included if written as number precise up to 2 decimal digits and multiples of 10. But the code generated writes it as a big fraction which, as you can imagine, takes a lot of space.

Any solutions for these two cases? Thank you.

Best Answer

I don't know of a way to solve 1, Matlab knows how to write to latex, but it is not a typesetting software.

However, 2 is possible and quite easy. You could use latexTable to convert your data to a table:

A = rand(4,5);
A(1,:) = A(1,:)*200;
A(3,:) = A(3,:)*10;
input.data = A;
input.dataFormat = {'%.2f'};
latext = latexTable(input);

in latext you now have

\begin{table}                               
\centering                                  
\begin{tabular}{|c|c|c|c|c|}                
\hline                                      
162.94 & 126.47 & 191.50 & 191.43 & 84.35 \\
\hline                                      
0.91 & 0.10 & 0.96 & 0.49 & 0.92 \\         
\hline                                      
1.27 & 2.78 & 1.58 & 8.00 & 7.92 \\         
\hline                                      
0.91 & 0.55 & 0.97 & 0.14 & 0.96 \\         
\hline                                      
\end{tabular}                               
\caption{MyTableCaption}                    
\label{table:MyTableLabel}                  
\end{table}