MATLAB help content for an abstract method
In ordinary class methods I can supply content for the "help" command in MATLAB. However, when writing an abstract method, the help function does not see the abstract methods. For example, if you have a class NeedsHelp:
classdef NeedsHelp开发者_如何学编程
methods (Abstract)
INeedHelp(self)
% This method is not visible to the help command.
end
methods
function IHaveHelp(self)
% This method shows help as expected.
end
end
end
The help command acts as follows (R2009b):
>> help NeedsHelp.IHaveHelp
This method shows help as expected.
>> help NeedsHelp.INeedHelp
NeedsHelp.INeedHelp not found.
Are there any solutions to providing documentation for abstract methods?
Put the help before the function line for abstract methods, just like you do for properties. I don't have 9b to test, but in 11b:
classdef NeedsHelp
methods (Abstract)
% Help goes here.
INeedHelp(self)
end
end
>> help NeedsHelp.INeedHelp
Help goes here.
I just ran into this problem. You can't do this in the actual class definition. There is a work-around (at least in 2012b) by using the fact that you can put Methods in Different Files and Class Precedence and MATLAB Path.
For the example, say you have your class file saved as
C:\myPath\NeedsHelp.m
To add the help file for the abstract method, first create a folder within the directory (myPath) which has the name of the class preceded by the @-symbol (@NeedsHelp). Within this folder create an M-File with the name of the abstract method (INeedHelp.m).
C:\myPath\@NeedsHelp\INeedHelp.m
This M-file contains only the "help" documentation. Because of the way class precedence works, the concrete methods of a subclass methods will be called, but when no "help" documentation is found, the @-folder is searched for a method definition.
The "help" documentation is inherited by both abstract and concrete subclasses and can be overwritten by both. Note that you don't have to put your class into the @-folder for this to work properly for the purpose of documentation.
(This is basically the way the "help" documentation is provided for built-in functions).
Looks like this is not possible as of R2009b, according to Loren's blog at The MathWorks. See this comment and her reply.
精彩评论