end
Terminate block of code or indicate last array index
Syntax
end
Description
end
also terminates a declared function. Although it is sometimes
optional, use end
for better code readability. end
is required in these cases:
If a file contains functions, and one of the functions is terminated with
end
, then every function in the file must be terminated withend
.If a file contains a function with one or more nested functions, then every function in the file must be terminated with
end
.If a script contains one or more local functions, then every function in the file must be terminated with
end
.
end
also represents the last index of an array. For example,
X(end)
is the last element of X
, and
X(3:end)
selects the third through final elements of
X
.
Examples
Tips
Classes can overload the
end
function to implement specialized behavior. For more information, see Overload end for Classes.If an array
X
already exists, you can useend
to grow the array size and append other elements to the array. For example,X(end+1) = 5
increases the length ofX
by 1 and adds a new element to the end ofX
.Although
end
is sometimes optional in a function file, use it for better code readability.
Extended Capabilities
Version History
Introduced before R2006a