MATLAB - 列出仅由子类提供的所有方法?

Dan*_*hoa 5 oop matlab

我有一个继承自多个超类的类,我想获得该类具有的方法.天真地使用methods()我正在使用的类中的返回方法以及超类方法,但我对超类方法不感兴趣.

知道怎么做吗?我在MATLAB文档中找不到任何内容.

谢谢!

gno*_*ice 3

如果您的子类没有重新实现超类的任何方法(或者您可以忽略重新实现的方法),则可以使用函数METHODSSUPERCLASSES来查找子类方法的列表,这些方法不是任何超类的方法的超类。例如:

>> obj = 'hgsetget';  %# A sample class name
>> supClasses = superclasses(obj)

supClasses = 

    'handle'    %# Just one superclass, but what follows should handle more

>> supMethods = cellfun(@methods,supClasses,...  %# Find methods of superclasses
                        'UniformOutput',false);
>> supMethods = unique(vertcat(supMethods{:}));  %# Get a unique list of
                                                 %#   superclass methods
>> subMethods = setdiff(methods(obj),supMethods)  %# Find methods unique to the
                                                  %#   subclass
subMethods = 

    'get'
    'getdisp'
    'set'
    'setdisp'
Run Code Online (Sandbox Code Playgroud)