MATLAB: How to list only those methods defined or overloaded in a certain classdef file

methodoop

Doing methods('myclass') will return the complete list of methods that myclass objects can invoke, including those inherited from superclasses. What can I do if I want to list only those methods implemented in the myclass.m classdef file itself?

Best Answer

As per commented, this can be done through meta objects,
function nameCell=methodslocal(classname)
%Return the names of non-Hidden methods defined
%or overloaded in the class called 'classname'
%
% nameCell=methodslocal(classname)
mcls = meta.class.fromName(classname);
ml=mcls.MethodList;
ml=ml(~[ml.Hidden]);
N=numel(ml);
for i=N:-1:1,
c{i}=ml(i).DefiningClass.Name;
end
lidx = strcmp(c,classname);
nameCell=sortrows({ml(lidx).Name}.').';