The Live Editor provides another very convenient way to create, edit, and run matlab scripts. Live Editor allows you to create live scripts that combine code, formatted text, and graphics to generate clear professional materials.

Create Live Script:
To create a live script in the Live Editor, go to the Home tab and click New Live Script. You also can use the edit function in the Command Window. For example, type edit penny.mlx to open or create the file penny.mlx. To ensure that a live script is created, specify a .mlx extension. If an extension is not specified, matlab® defaults to a file with .m extension, which only supports plain code.

?????
?????

Open Existing Script as Live Script:
If you have an existing script, you can open it as a live script in the Live Editor. Opening a script as a live script creates a copy of the file and leaves the original file untouched. matlab converts publishing markup from the original script to formatted content in the new live script.

?????
To open an existing script (.m) as a live script (.mlx) from the Editor, right-click the document tab, and select Open scriptName as Live Script from the context menu. Alternatively, go to the Editor tab, click Save, and select Save As. Then, set the Save as type: to matlab Live Code Files (*.mlx) and click Save.

?????
?????

Add Code:
After you create a live script, you can add code and run it. For example, add this code that plots

????
?????

Run Code:
To run the code, click the vertical striped bar to the left of the code. Alternatively, go to the Live Editor tab and click Run. While your program is running, a status indicator appears at the top left of the Editor window. A gray blinking bar to the left of a line of code indicates the line that MATLAB is evaluating. To navigate to the line MATLAB is evaluating, click the status indicator. If an error occurs while matlab is running your program or if matlab detects a significant issue in your code, the status indicator becomes an error icon . To navigate to the error, click the icon. An error icon to the right of the line of code indicates the error. The corresponding error message is displayed as an output. You do not need to save your live script to run it. When you do save your live script, matlab automatically saves it with a .mlx extension. For example, go the Live Editor tab, click Save, and enter the name plotRand. matlab saves the live script as plotRand.mlx.

Display Output:
By default, matlab displays output to the right of the code. Each output is displayed with the line that creates it. When scrolling, matlab aligns the output to the code that generates it. To disable the alignment of output to code, right-click the output section and select Disable Synchronous Scrolling. To change the size of the output display panel, drag the resizer bar between the code and output to the left or to the right.

To clear an output, right-click the output or the code line that created it, and select Clear Output. To clear all output, right-click anywhere in the script and select Clear All Output. Alternatively, go to the View tab and in the Output section, click the Clear all Output button.

?????

To open individual outputs, such as variables and figures, in a separate window, click the button in the upper right corner of the output. Variables open in the Variables editor, and figures open in a new figure window. Changes made to variables or figures outside of a live script do not apply to the output displayed in the live script. To modify figures in the output, use the tools in the upper-right corner of the figure axes or in the Figure toolstrip. You can use the tools to explore the data in a figure and add formatting and annotations. For more information, see Modify Figures in Live Scripts.

Change View:
To optimize your live script for your current flow, you can change where to display output and whether to display code in the live script. By default, output displays to the right of the code. Each output displays with the line that creates it. This option is ideal when writing code.

To display output in line with the code, select the output inline button to the right of the live script. You also can go to the View tab and in the View section, select the Output inline button. MATLAB displays each output underneath the line that creates it. This view is ideal for sharing. To change the default location of the output when creating a new live script, on the Home tab, in the Environment section, click Preferences. Select matlab > Editor / Debugger > Display, and then select a different option for the Live Editor default view.