Reputation: 11
I have a class in MATLAB that uses a class method for specialized indexing into the class data. I am interested in overloading the end(obj, k, n) method so that it is easy to write indexing expressions into this method, but I have already overloaded this function for use in subsref(obj, s).
Could someone please explain to me how MATLAB calls the end method in the following:
>> obj = myClass; obj.myIndexMethod(1:end)
Upvotes: 0
Views: 65
Reputation: 24127
end
is implemented as a function ind = end(obj, k, n)
. k
is the index of the expression containing end
, and n
is the total number of indices in the expression.
So, for example, when you call a(1,end,1)
, k
is 2, as the end
is in argument 2, and n
is 3 as there are 3 arguments.
ind
is returned as the index that can replace end
in the expression.
Upvotes: 1