我有一个Super类,已经做了一些详尽的文档。有一些子类继承自该父类(super class),如果可能的话,我想重用该父类(super class)的文档。例如, super 类ClassA:

classdef ClassA
    %CLASSA Super Class for all others classes
    %
    % CLASSA Properties:
    %   Prop1       It's the first property
    %   Prop2       It's the second
    %
    % CLASSA Methods:
    %   Method1     It's a method
    %   Method2     It's another method

    function value = Method1(var)
        % Super implementation of Method1
    end

    % Other method definitions follow
end

还有一个子类,ClassB:
classdef ClassB < ClassA
    %CLASSB Subclass of super class CLASSA
    %
    % CLASSB Properties:
    %   Prop3       It's the first property of subclass
    %
    % CLASSB Methods:
    %   Method 3    It's the first method of subclass

    function value = Method1(var)
        % Subclass implementation of Method1
    end

    % Other method definitions follow
end

如果键入help ClassB,则只会得到ClassB的帮助说明。我还希望包含 super 帮助的描述。输出看起来像这样:
 CLASSB Subclass of super class CLASSA

 CLASSB Properties:
    Prop1       It's the first property
    Prop2       It's the second
    Prop3       It's the first property of subclass

 CLASSB Methods:
    Method1     It's a method
    Method2     It's another method
    Method3     It's the first method of subclass

有没有办法做到这一点?

最佳答案

@SamRoberts所指出的,存在一个记录属性和方法的standard way

例如:

classdef Super
    %Super Summary of this class goes here
    %   Detailed explanation goes here
    %
    % Super Properties:
    %    One - Description of One
    %    Two - Description of Two
    %
    % Super Methods:
    %    myMethod - Description of myMethod
    %

    properties
        One     % First public property
        Two     % Second public property
    end
    properties (Access=private)
        Three   % Do not show this property
    end

    methods
        function obj = Super
            % Summary of constructor
        end
        function myMethod(obj)
            % Summary of myMethod
            disp(obj)
        end
    end
    methods (Static)
        function myStaticMethod
            % Summary of myStaticMethod
        end
    end

end


classdef Derived < Super
    %Derived Summary of this class goes here
    %   Detailed explanation goes here
    %
    % See also: Super

    properties
        Forth     % Forth public property
    end

    methods
        function obj = Derived
            % Summary of constructor
        end
        function myOtherMethod(obj)
            % Summary of myMethod
            disp(obj)
        end
    end

end

现在在命令行上,您可以说:

您会获得格式正确的超链接。

还要注意doc Derived(或突出显示单词并按F1键)会得到什么。这在内部调用help2html将帮助转换为HTML。例如,我们可以自己做:
>> %doc Derived
>> web(['text://' help2html('Derived')], '-noaddressbox', '-new')

请注意,将显示继承的属性/方法。

关于matlab - 如何从Matlab的父类(super class)继承文档?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16423515/

10-14 10:47