Main Content

What Is a Live Script or Function?

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.

Live script with two outputs. Each output is displayed to the right of the code that produced it.

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 HTML, PDF,Microsoft®Word, or LaTeX documents for publication.

Live script with a heading, image, descriptive text with formatted equations, and code

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 script containing a homework assignment with three exercises and text inviting the user to complete the exercises by adding code and text directly to the live script

差异与纯代码脚本和函数

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, seeLive Code File Format (.mlx) Plain Text file format
File Extension .mlx .m
Output Display With code in the Live Editor (live scripts only) In Command Window
Text Formatting Add and view formatted text in the Live Editor Use publishing markup to add formatted text, publish to view
Visual Representation

Live script with code, output, and formatted text

Plain code script showing code and green commented text

Requirements

  • MATLAB R2016a — MATLAB supports live scripts in versions R2016a and above, and live functions in versions R2018a and above.

  • Operating System — Starting in R2019b, MATLAB supports the Live Editor in all operating systems supported by MATLAB. For more information, seeSystem Requirements.

    For MATLAB versions R2016a through R2019a, the Live Editor is not supported in several operating systems supported by MATLAB.

    Unsupported operating systems 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.

    In addition, some operating systems require additional configuration to run the Live Editor in MATLAB versions R2016a through R2019a. If you are unable to run the Live Editor on your system,Contact Technical Supportfor information on how to configure your system.

Unsupported Features

Some MATLAB features are unsupported in the Live Editor:

  • Classes — Classes are not supported in the Live Editor. Create classes as plain code files (.m)。然后您可以使用在你的类ve scripts or functions.

  • MATLAB preferences — The Live Editor ignores some MATLAB preferences, including custom keyboard shortcuts and Emacs-style keyboard shortcuts.

Related Topics