MATLAB scripts are written in plain text .m files, which can be difficult to read and do not contain any of the results from running the script. Publishing the script converts the plain text to rich text PDFs that are easy to read and contain the results. With the Boeing 737 center-of-mass example from the User Scripts page, the comments certainly clarify what the script is doing, but it would be easier to read as a PDF. A PDF is also easier to share with someone who does not have MATLAB installed, or does not have time to rerun your script if it contains slow operations.

To convert a script into a PDF (or other formats), use the publish command. For example:

publish('center_of_mass_737.m', 'pdf');

The PDF produced by this command is center_of_mass_737.pdf.

Unable to display PDF.

MATLAB provides more details on the publishing process on their publish page. For more information on formatting text in the comments, visit Publishing Markup.