MATLAB® live scripts and live functions are interactive documents that combine MATLAB code with formatted text, equations, and images in a single environment called the Live Editor. In addition, live scripts store and display output alongside the code that creates it.
Use live scripts and functions 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 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
LaTeX files for
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 hard copy format, and distribute partially completed files as assignments.
Live scripts and live functions differ from plain code scripts and functions in several ways. This table summarizes the main differences.
|Live Scripts and Functions||Plain Code Scripts and Functions|
|File Format||Live Code file format. For more information, see Live Code File Format (.mlx)||Plain Text file format|
|Output Display||With code in the Live Editor (live scripts only)||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 the Live Editor||Use publishing markup to add formatted text, publish to view|
R2016a — MATLAB supports live scripts in versions
R2016a and above, and live functions in versions
R2018a and above.
Operating System — MATLAB supports the Live Editor in most of the operating systems supported by MATLAB. For more information, see System Requirements. There are several operating systems supported by MATLAB that the Live Editor does not support.
Unsupported versions include:
Red Hat Enterprise Linux 6.
Red Hat Enterprise Linux 7.
SUSE Linux Enterprise Desktop versions 13.0 and earlier.
Debian 7.6 and earlier.
Some operating systems require additional configuration to run the Live Editor. If you are unable to run the Live Editor on your system, Contact Technical Support for information on how to configure your system.
When deciding whether to create a live script or function, it is important to note several unsupported features in the Live Editor:
Classes — Classes are not supported in the Live Editor. Create
classes as plain code files (
.m) instead. You then
can use the classes in your live scripts or functions.
Editor preferences — The Live Editor ignores most Editor preferences, including custom keyboard shortcuts and Emacs-style keyboard shortcuts.
To save a live script or function as a plain code file
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.
When saving, MATLAB converts all formatted content to publish markup.