Lesson 1.7 – Publishing an m-file

Learning Objectives

After reading this lesson, you should be able to:

  1. know why MATLAB is useful for engineers and scientists,

  2. know how to get MATLAB on your computer,

  3. comprehend the free alternatives to MATLAB.


What does publishing do?

Publishing does several helpful things for you if you make good use of sections. Each of the following reflects the use of sections to split up different portions of the m-file (e.g., different exercises). 

Figure 1: Example of published format.

A published file:

  • Automatically links the sections contained in the m-file at the top of the published file. Click the link, and it takes you to that section. 

  • Can be saved in multiple file formats including .html and .pdf. 

  • Highlights each section and displays outputs directly below it.

  • Shows comments as a description for each section (see below).


How can I publish in MATLAB?

In the toolbar, select the “PUBLISH” tab. Then click the “Publish” button on the far right of this figure.

Figure 2: Publish tab in MATLAB toolbar. 


How can I get a PDF file of my published code?

You have two options to get a pdf. You can either change the publish settings to publish natively in pdf, or you can convert the html file into pdf using your internet browser.

  1. Publish as HTML (default) Then Convert to PDF - Here are a couple of tips for converting from html to pdf. Keep in mind you can open the .html file in your web browser. So, you should start by doing that.

    For Chrome and Microsoft Edge, go to print, click “Change” to change printer, then click “Save as PDF” (for Chrome) or “Microsoft Print to PDF” (for Edge), and select where to save the .pdf file. Other browsers should have a similar procedure to save a .html file.

  2. Publish Directly as a PDF - Click the arrow under Publish (seen in Figure 2) to open “Edit Configurations” (see Figure 3). Then change “Output file format” from html to pdf. Remember, it will be html by default.

Figure 3: Edit publishing configurations window where you can change the output file format.


Lesson Summary of New Syntax and Programming Tools

Task Syntax Example Usage
Create a new section %% %% section name

Multiple Choice Quiz

The content of this page is intentionally blank

Problem Set

The content of this page is intentionally blank