3

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.

Zero
  • 165
  • 1
    Can you use Matlab to generate an output with floating-point numbers truncated up to two significant digits? – Matsmath Jun 12 '16 at 20:23
  • @Matsmath yeah i get what you mean but how do I get to the number of decimal places that I want. e.g. 34.2163 and 0.0236 will give me 34 and 0.02 but I want 34.21 and 0.02 – Zero Jun 12 '16 at 23:20

1 Answers1

3

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}  
Elad Den
  • 3,941