How can I create a table and publish it to PDF using the "publish" function?

32 Ansichten (letzte 30 Tage)
How do I include a nicely formatted table in my PDF report generated using the "publish" function in MATLAB?  I tried using LaTeX markups and publish to a PDF file in MATLAB, but the code between the markups is ignored.

Akzeptierte Antwort

MathWorks Support Team
MathWorks Support Team am 18 Okt. 2013
When using the MATLAB "publish" function or the Publish icon on the PUBLISH Toolstrip, you can automatically publish your code for sharing. By default, the output format is HTML, but you can select other formats, such as LaTeX or PDF.
LaTeX offers a convenient way to create tables. LaTeX code can be inserted in your MATLAB file by adding LaTeX markups around it. 
For instance, the following code creates a table using the LaTeX syntax and surrounds it with LaTeX markups:
 
 %% LaTeX Markup Example
   % This is a table:
   %
   % <latex>
   % \begin{tabular}{|c|c|} \hline
   % $n$ & $n!$ \\ \hline
   % 1 & 1 \\
   % 2 & 2 \\
   % 3 & 6 \\ \hline
   % \end{tabular}
   % </latex>
 
However, the code between the markups is only published when the output format specified for "publish" is explicitly set to LaTeX. When trying to publish this code to a PDF file, the code between the markups will be ignored.To generate a PDF file where the table appears, you can use LaTeX markups as above and publish your MATLAB code to LaTeX. This will generate a LaTeX file that can be readily compiled to a PDF file with a LaTeX compiler. 
Another possibility is to use a MATLAB "uitable" object on a figure as follows:
   data =  {1, 1 ;
            2, 2 ;
            3, 6};
   columnName =   {'n', 'n!'};
   fh = figure;
   t = uitable('Units','normalized','Position',...
      [0 0 1 1], 'Data', data,... 
      'ColumnName', columnName,...
      'RowName',[]);
   figPos = get(fh,'Position');
   tableExtent = get(t,'Extent');
   set(fh,'Position',[figPos(1:2), figPos(3:4).*tableExtent(3:4)]);
When publishing to a PDF file, MATLAB will include the figure on the generated PDF file. However, the code that generates the figure will also appear in the PDF. To prevent the code from appearing, you can save it to a separate MATLAB script with an appropriate name (for instance Factorial_Table.m) and call this script in the MATLAB script that you wish to publish. In the resulting PDF file, you will see the single command that calls your MATLAB script and the table generated.

Weitere Antworten (0)

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by