Run Sections in Live Scripts

Divide Your File Into Sections

Live scripts often contain many commands and lines of text. You typically focus efforts on a single part of your program at a time, working with the code, and related text in pieces. For easier document management and navigation, divide your file into sections. Code, output, and related text can all appear together, in a single section.

To insert a section break into your live script, go to the Live Editor tab and in the Section section, click the Section Break button. The new section is highlighted in blue, indicating that it is selected. A vertical striped bar to the left of the section indicates that the section is stale. A stale section is a section that has not yet been run, or that has been modified since it was last run.

This image shows a new blank section in a live script.

To delete a section break, click the beginning of the line directly after the section break and press Backspace. You also can click the end of the line directly before the section break and press Delete.

Evaluate Sections

Run your live script either by evaluating each section individually or by running all the code at once. To evaluate a section individually, it must contain all the values it requires, or the values must exist in the MATLAB® workspace. Section evaluation runs the currently selected section, highlighted in blue. If there is only one section in your program file, the section is not highlighted, as it is always selected.

This table describes different ways to run your code.

OperationInstructions
Run the code in the selected section.

Click the blue bar to the left of the section.

OR

On the Live Editor tab, in the Section section, click Run Section.

Run the code in the selected section, and then move to the next section.

On the Live Editor tab, in the Section section, select Run and Advance.

Run the code in the selected section, and then run all the code after the selected section.

On the Live Editor tab, in the Section section, select Run to End.

Run all the code in the file.

On the Live Editor tab, in the Run section, click Run.

Related Topics