|MATLAB Function Reference|
Terminate block of code, or indicate last index of array
end is used to terminate
if statements. Without an
if wait for further input. Each
end is paired with the closest previous unpaired
if and serves to delimit its scope.
end also marks the termination of an M-file function, although in most cases, it is optional.
end statements are required only in M-files that employ one or more nested functions. Within such an M-file, every function (including primary, nested, private, and subfunctions) must be terminated with an
end statement. You can terminate any function type with
end, but doing so is not required unless the M-file contains a nested function.
end function also serves as the last index in an indexing expression. In that context,
end = (size(x,k)) when used as part of the
kth index. Examples of this use are
X(1,1:2:end-1). When using
end to grow an array, as in
X(end+1)=5, make sure
X exists first.
You can overload the
end statement for a user object by defining an
end method for the object. The
end method should have the calling sequence
obj is the user object,
k is the index in the expression where the
end syntax is used, and
n is the total number of indices in the expression. For example, consider the expression
MATLAB will call the
end method defined for
A using the syntax
This example shows
end used with the
In this example,
end is used in an indexing expression.
© 1994-2005 The MathWorks, Inc.