A MATLAB® live script is an interactive document that combines MATLAB code
with embedded output, formatted text, equations, and images in a single
environment called the Live Editor. Live scripts are stored using
the Live Script file format in a file with a .mlx
extension.
Use live scripts to
Visually explore and analyze problems
Write, execute, and test code in a single interactive environment.
Run blocks of code individually or as a whole file, and view the results and graphics with the code that produced them.
Share richly formatted, executable narratives
Add titles, headings, and formatted text to describe
a process and include LaTeX
equations, images,
and hyperlinks as supporting material.
Save your narratives as richly formatted, executable
documents and share them with colleagues or the MATLAB community,
or convert them to HTML
or PDF
files
for publication.
Create interactive lectures for teaching
Combine code and results with formatted text and mathematical equations.
Create step-by-step lectures and evaluate them incrementally to illustrate a topic.
Modify code on the fly to answer questions or explore related topics.
Share lectures with students as interactive documents or in hardcopy format, and distribute partially completed files as assignments.
Live scripts differ from plain code scripts in several ways. This table summarizes the main differences.
Live Script | Script | |
---|---|---|
File Format | Live Script file format. For more information, see Live Script File Format (.mlx) | Plain Text file format |
File Extension | .mlx | .m |
Output Display | With code in Editor | In Command Window |
Internationalization | Interoperable across locales | Non-7–bit ASCII characters are not compatible across all locales |
Text Formatting | Add and view formatted text in Editor | Use publishing markup to add formatted text, publish to view |
Visual Representation |
|
|
MATLAB R2016a
— MATLAB supports
live scripts in versions R2016a
and above. You
can open live scripts as code only files in MATLAB versions R2014b
, R2015a
,
and R2015b
.
Caution
Saving a live script in MATLAB versions |
Operating System — MATLAB supports live scripts in most of the operating systems supported by MATLAB. For more information, see System Requirements.
Unsupported versions include:
Red Hat Enterprise Linux 6.
SUSE Linux Enterprise Desktop versions 13.0 and earlier.
Debian 7.6 and earlier.
When deciding whether to create a live script, it is important to note several features that the Live Editor does not support:
Functions and classes — The Live Editor only
supports functions in live scripts. You can create functions in the
Live Editor by including them at the end of a live script. For more
information, see Add Functions to Scripts. To create class or function
files, create them as plain code files (.m
). You
then can call the functions and classes from your live scripts.
Debugging using the graphical debugger — In
the Live Editor, you cannot set breakpoints graphically or pause the
execution of a live script using the Pause button.
To debug your file, see Debugging in live scripts. Alternatively,
you can Save
your live script as a plain code file (.m
).
If a breakpoint is placed in a plain code file (.m
)
that is called from a live script, MATLAB ignores the breakpoint
when the live script is executed.
Editor preferences — The Live Editor ignores most Editor preferences, including custom keyboard shortcuts and Emacs-style keyboard shortcuts.
Generating Reports — MATLAB does not include live scripts when generating reports. This includes Code Analyzer, TODO/FIXME, Help, Contents, Dependency, and Coverage reports.
To save a live script as a plain code file (.m
).
On the Live Editor tab, in the File section, select Save > Save As....
In the dialog box that appears, select MATLAB
Code files (*.m)
as the Save as type.
Click Save.
When saving, MATLAB converts all formatted content to publish markup.