Operation
Instructions
Move to specific section.
On the Editor or Live Editor tab, in the Navigate section, click
Go To . Then, in the Sections section, select from the available
options.
Move to previous section.
On the Editor or Live Editor tab, in the Navigate section, click
Go To , and then click Previous Section. Alternatively, you can use
the Ctrl+Up keyboard shortcut.
Move to next section
On the Editor or Live Editor tab, in the Navigate section, click
Go To , and then click Next Section. Alternatively, you can use the
Ctrl+Down keyboard shortcut.
Behavior of Sections in Functions
In the Editor, if you add a section break within a function, MATLAB inserts section breaks at the
function declaration and at the function end statement. If you do not end the function with an end
statement, MATLAB behaves as if the end of the function occurs immediately before the start of the
next function.
In the Live Editor, you cannot add section breaks inside a function. Sections inside local functions are
not supported. If you add local functions to a live script, MATLAB adds a section break before the first
local function definition and removes all section breaks after it. When running individual sections in a
live script, you can run only the sections that are before the local function definitions.
Behavior of Sections in Loops and Conditional Statements
In the Editor, if you add a section break within a loop or conditional statement (such as an if
statement or for loop), MATLAB adds section breaks at the lines containing the start and end of the
statement (if those lines do not already contain a section break). The sections within the loop or
conditional statement are independent from the sections in the remaining code and become nested
inside the sections in the remaining code. Sections inside nested loop or conditional statements also
become nested.
For example, this code preallocates a 10-element vector, and then calculates nine values. If a
calculated value is even, MATLAB adds one to it.
x = ones(1,10);
for n = 2:10
x(n) = 2 * x(n - 1);
if rem(x(n), 2) == 0
x(n) = x(n) + 1;
end
end
If you add a section break at line 3, inside the for loop, MATLAB adds a section break at line 9, the
end statement for the for loop. If you add a section break at line 6, inside the if statement, MATLAB
adds a section break at line 8, the end statement for the if statement, leading to three levels of
nested sections.
18 Scripts
18-8
Instructions
Move to specific section.
On the Editor or Live Editor tab, in the Navigate section, click
Go To . Then, in the Sections section, select from the available
options.
Move to previous section.
On the Editor or Live Editor tab, in the Navigate section, click
Go To , and then click Previous Section. Alternatively, you can use
the Ctrl+Up keyboard shortcut.
Move to next section
On the Editor or Live Editor tab, in the Navigate section, click
Go To , and then click Next Section. Alternatively, you can use the
Ctrl+Down keyboard shortcut.
Behavior of Sections in Functions
In the Editor, if you add a section break within a function, MATLAB inserts section breaks at the
function declaration and at the function end statement. If you do not end the function with an end
statement, MATLAB behaves as if the end of the function occurs immediately before the start of the
next function.
In the Live Editor, you cannot add section breaks inside a function. Sections inside local functions are
not supported. If you add local functions to a live script, MATLAB adds a section break before the first
local function definition and removes all section breaks after it. When running individual sections in a
live script, you can run only the sections that are before the local function definitions.
Behavior of Sections in Loops and Conditional Statements
In the Editor, if you add a section break within a loop or conditional statement (such as an if
statement or for loop), MATLAB adds section breaks at the lines containing the start and end of the
statement (if those lines do not already contain a section break). The sections within the loop or
conditional statement are independent from the sections in the remaining code and become nested
inside the sections in the remaining code. Sections inside nested loop or conditional statements also
become nested.
For example, this code preallocates a 10-element vector, and then calculates nine values. If a
calculated value is even, MATLAB adds one to it.
x = ones(1,10);
for n = 2:10
x(n) = 2 * x(n - 1);
if rem(x(n), 2) == 0
x(n) = x(n) + 1;
end
end
If you add a section break at line 3, inside the for loop, MATLAB adds a section break at line 9, the
end statement for the for loop. If you add a section break at line 6, inside the if statement, MATLAB
adds a section break at line 8, the end statement for the if statement, leading to three levels of
nested sections.
18 Scripts
18-8
