Main Content

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 theLive Editortab and in theSectionsection, click theSection Breakbutton. 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 isstale. 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 pressBackspace. You also can click the end of the line directly before the section break and press删除.

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.

Operation Instructions
Run the code in the selected section.

Click the blue bar to the left of the section.

OR

On theLive Editortab, in theSectionsection, clickRun Section.

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

On theLive Editortab, in theSectionsection, selectRun and Advance.

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

On theLive Editortab, in theSectionsection, selectRun to End.

Run all the code in the file.

On theLive Editortab, in theRunsection, clickRun.

Related Topics