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 Share | Instructions |
---|---|
Share files directly. | Distribute the live code files ( MATLAB supports live scripts starting in R2016a and live functions starting in R2018a. |
Export files to documents viewable outside of MATLAB. Supported formats include:
| 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)
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 Alternatively, you can use the |
To export your live scripts or functions programmatically, use
the When using the
| |
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
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 |
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.