If your class implements an end method, ensure that it returns a value appropriate for the
class.
The end Method
The end method for the MyDataClass example (see “Class with Modified Indexing” on
page 17-39) operates on the contents of the Data property. The objective of this method
is to return a value that can replace end in any indexing expression, such as:
obj(4:end)
obj.Data(2,3:end)
This end method determines a positive integer value for end. The method returns the
value so that MATLAB can use it in the indexing expression.
function ind = end(obj,k,n)
szd = size(obj.Data);
if k < n
ind = szd(k);
else
ind = prod(szd(k:end));
end
end
See Also
Related Examples
- “Class with Modified Indexing” on page 17-39
- “Objects in Index Expressions” on page 17-37
17 Specialize Object Behavior