Main Content

Ways to Share and Export Live Scripts and Functions

You can share live scripts and functions with others for teaching or demonstration purposes, or to provide readable, external documentation of your code.

This table shows the different ways to share live scripts and functions.

Ways to ShareInstructions
Share files directly.

Distribute the live code files (.mlx). Recipients of the files can open and view them in MATLAB® in the same state that you last saved them, including any generated output.

MATLAB supports live scripts starting in R2016a and live functions starting in R2018a.

Export files to documents viewable outside of MATLAB.

Supported formats include:

  • PDF

  • Microsoft® Word

  • HTML

  • LaTeX

  • Markdown

  • Jupyter® notebooks

To export your live scripts or functions interactively, on the Live Editor tab, select Export and then select a format. Supported formats for interactive export include PDF, Microsoft Word, HTML, and LaTeX. To export all of the live scripts and functions in a folder, on the Live Editor tab, select Export > Export Folder. To export in MATLAB Online™, select Save instead of Export.

In the Export dialog box that opens, you can customize the export options. (since R2023b)

  • Change the paper size, orientation, and margins when exporting to PDF, Microsoft Word, and LaTeX.

  • Change the resolution and format of figures when exporting to PDF, HTML, and LaTeX (requires the files to be run before exporting).

The converted files closely resemble the appearance of the live scripts or functions when viewed in the Live Editor with output inline. If the live scripts contain controls or tasks, the Live Editor saves them as code in the converted files.

When exporting to LaTeX, MATLAB creates a separate matlab.sty file in the same folder as the converted files, if one does not exist already. STY files, also known as LaTeX Style documents, give you more control over the appearance of the converted files.

Alternatively, you can use the matlab.editor export settings to customize the converted files before exporting.

To export your live scripts or functions programmatically, use the export function. Supported formats for programmatic export include PDF, Microsoft Word, HTML, LaTeX, Markdown, and Jupyter notebooks.

When using the export function, you can customize the converted file using name-value arguments. For example, you can hide the code in the converted file, as well as customize the resolution and format of figures, and the document paper size, orientation, and margins.

Show the files as a full-screen presentation.

With a live script or function open in the Live Editor, go to the View tab and click the Full Screen button on. The Live Editor shows the file in full-screen mode.

To exit full-screen mode, move the mouse to the top of the screen to display the View tab and click the Full Screen button off.

Save the files as MATLAB plain code files (.m).

With a live script or function open in the Live Editor, on the Live Editor tab, in the File section, select Save > Save As. In the dialog box that appears, select MATLAB Code files (UTF-8) (*.m) from the Save as type list.

When you distribute the file, recipients can open and view the file in MATLAB. MATLAB converts formatted content from the live script or function to publishing markup in the new script or function.

To save your live scripts or functions as plain code files programmatically, use the export function and specify the Format name-value argument as "m".

Hide Code Before Sharing

Before sharing or exporting your live scripts, consider hiding the code. When you hide the code in a live script, the Live Editor displays only output, labeled controls, tasks, and formatted text. If a task in the live script is configured to show only code and no controls, then the task does not display when you hide the code. Hiding the code is useful when sharing if you want others to change only the value of the controls in your live script or when you do not want others to see your code.

To hide the code, click the Hide code button to the right of the live script. You also can go to the View tab, and in the View section, click Hide Code . To show the code again, click the Output inline button or the Output on right button . Alternatively, if you are using the export function to share your live script, you can hide the code using the HideCode name-value argument.

Note

When exporting to PDF, Microsoft Word, HTML, LaTeX, Markdown, or Jupyter notebooks, the Live Editor saves controls and tasks as code. If you have a live script that contains controls and tasks and you hide the code before exporting, the converted file does not contain the controls or tasks.

See Also

Functions

Settings

Related Topics