MATLAB allows overloading various operators for custom classes. One of the unlisted overloadable operators is end
, as can be learned from \matlab\lang\end.m
:
% END(A,K,N) is called for indexing expressions involving the object A
% when END is part of the K-th index out of N indices. For example,
% the expression A(end-1,:) calls A's END method with END(A,1,2).
An example of such a method is table.end
(paste in the MATLAB command line and press "Open Selection" to go to its definition; it is defined in ...\matlab\datatypes\@tabular\end.m
).
Unlike a normal method, one cannot simply write hEnd = @end
, because this gives the error:
>> hEnd = @end;
hEnd = @end;
↑
Error: Illegal use of reserved keyword "end".
On the other hand, writing e = str2func('end');
works, but it links to the default end
function (even when temporarily switching to the folder where the desired end.m
is found).
Failed attempts include str2func('table>end');
, str2func('table\end');
, str2func('table.end');
and @(a,b,c)table.end(a,b,c);
.
My question: How do I create a handle to the end
function of a specific class?