Skip to main content
Engineering LibreTexts

1.8: Publishing with MATLAB

  • Page ID
    9466
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    屏幕快照 2019-05-29 10.24.20.png

    MATLAB includes an automatic report generator called publisher. The publisher publishes a script in several formats, including HTML, XML, MS Word and PowerPoint. The published file can contain the following:

    • Commentary on the code,
    • MATLAB code,
    • Results of the executed code, including the Command Window output and figures created by the code.

    The

    publish
    

    Function

    The most basic syntax is publish('file','format') where the m-file is called and executed line by line then saved to a file in specified format. All published files are placed in the html directory although the published output might be a doc file.

    Publishing with Editor

    The publisher is easily accessible from the Tool Strip:

    屏幕快照 2019-05-29 10.25.27.png

    Figure \(\PageIndex{1}\). Publish tab on the Tool Strip.

    屏幕快照 2019-05-29 10.26.35.png

    Figure \(\PageIndex{2}\). Editing publishing options, currently output format is html.

    Write a simple script and publish it in an html file.

    Select File > New > Script to create an m-file. Once the editor is opened, type in the following code:

    ParseError: invalid XmlNode (click for details)
    Callstack:
        at (Bookshelves/Computer_Science/Applied_Programming/Book:_A_Brief_Introduction_to_Engineering_Computation_with_MATLAB_(Beyenir)/01:_Chapters/1.08:_Publishing_with_MATLAB), /content/body/div/div/div[2]/div[1]/div/pre, line 4, column 4
    

    Save the script as publishing.m and select Publish > Publish.

    屏幕快照 2019-05-29 10.28.28.png

    Figure \(\PageIndex{3}\). Publishing a script.

    An HTML file is generated as shown in the figure below:

    屏幕快照 2019-05-29 10.29.43.png

    Figure \(\PageIndex{4}\). A script published in html

    The Double Percentage

    %%
    

    Sign

    The scripts sometimes can be very long and their readability might be reduced. To improve the publishing result, sections are introduced by adding descriptive lines to the script preceded by %%. Consider the following example.

    Edit the script created in the example above to look like the code below:

    ParseError: invalid XmlNode (click for details)
    Callstack:
        at (Bookshelves/Computer_Science/Applied_Programming/Book:_A_Brief_Introduction_to_Engineering_Computation_with_MATLAB_(Beyenir)/01:_Chapters/1.08:_Publishing_with_MATLAB), /content/body/div/div/div[3]/div/div/pre, line 6, column 4
    

    Save the script, a new HTML file is generated as shown in the figure below:

    屏幕快照 2019-05-29 10.32.14.png

    Figure \(\PageIndex{5}\). An html file with sections

    Summary of Key Points

    1. MATLAB can generate reports containing commentary on the code, MATLAB code and the results of the executed code,
    2. The publisher generates a script in several formats, including HTML, XML, MS Word and PowerPoint.
    3. The Double Percentage %% can be used to creates hyper-linked sections.

    This page titled 1.8: Publishing with MATLAB is shared under a CC BY 4.0 license and was authored, remixed, and/or curated by Serhat Beyenir via source content that was edited to the style and standards of the LibreTexts platform; a detailed edit history is available upon request.

    • Was this article helpful?