gpt4 book ai didi

matlab - 我如何从 Matlab 中的父类(super class)继承文档?

转载 作者:太空宇宙 更新时间:2023-11-03 19:42:01 26 4
gpt4 key购买 nike

我有一个 super 类,我已经对其进行了一些广泛的说明。有些子类继承自这个父类(super class),如果可能的话,我想重用父类(super class)的文档。例如父类(super class)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

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

help_super

您会得到格式良好的超链接。

还要注意使用 doc Derived(或者当您突出显示该词并按 F1 时)会得到什么。这在内部调用 help2html 将帮助转换为 HTML。例如,我们可以自己做:

>> %doc Derived
>> web(['text://' help2html('Derived')], '-noaddressbox', '-new')

web

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

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

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com