This is the problem:

  1. Create a class and set the access to be private for some of the properties or methods.
  2. Use the doc command for the created class. This will auto-generate documentation from your comments and show it in the built-in help browser.

    doc classname

The problem is that documentation for the private properties and methods is not shown in the help browser. Is there any way to overcome this problem?

有帮助吗?

解决方案

So I spent like 10 minutes using the debugger, jumping from one function to the next, tracing the execution path of a simple doc MyClass call.

Eventually it lead me to the following file:

fullfile(toolboxdir('matlab'),'helptools','+helpUtils','isAccessible.m')

This function is called during the process of generating documentation for a class to determine if the class elements (including methods, properties, and events) are publicly accessible and non-hidden. This information is used later on to "cull" the elements.

So if you are willing to modify MATLAB's internal functions, and you want the docs to always show all methods and properties regardless of their scope, just rewrite the function to say:

function b = isAccessible(classElement, elementKeyword)
    b = true;
    return

    % ... some more code we'll never reach!
end

Of course, don't forget to make a backup of the file in case you changed your mind later :)

(on recent Windows, you'll need to perform this step with administrative privileges)


As a test, take the sample class defined in this page and run doc someClass. The result:

doc someClass

其他提示

This behaviour is by design - the auto-generated documentation is intended for users of the class, who would only be able to access the public properties and methods.

There's no way that I'm aware of to change this behaviour.

You could try:

  1. Use an alternative system of auto-generating documentation such as this from the MATLAB Central File Exchange (which I believe will document all properties, not just public).
  2. Implement your own doc command. Your doc command should accept exactly the same inputs as the built-in doc command, detect if its inputs correspond to your class/methods/properties etc, and if so display their documentation, otherwise pass its inputs straight through to the built-in doc. Make sure your command is ahead of the built-in on the path.
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top