Search code examples
matlaboopdocumentationprivate-members

MATLAB doesn't show help for user-created class private methods and properties


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?


Solution

  • 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