How to do method documentation for Classes/Handles just as normal functions in m files?

7 visualizaciones (últimos 30 días)
When working with many methods in a given class or handle class it would be convenient to be able to see the list of inputs i.e. the documentation of the method. If I have an instance of a handle class called "C2" with method "RunAnalysis", then when I press the "F1" key, the help menu will say:
" MATLAB File Help
C2.RunAnalysis
No help found for C2.RunAnalysis.
Search for C2.RunAnalysis in documentation "
How do I do method documentation for Classes/Handles just as normal they would appear when I press "F1" key for normal functions in m files?

Respuestas (1)

Suraj Mankulangara
Suraj Mankulangara el 2 de Abr. de 2018
Hello Yasen
You can provide help text for a function or class by doing the following:
1) Below the class or function definition line (i.e. below the lines containing the "classdef" or "function" declarations), add a line with "%%" followed by a space, and write your help text there 2) If you would like to spread the help text over multiple lines, you could add "%" lines below (followed by space), and they will be shown in the description of the class or function.
The following link should give you a better idea of how to go about this:
For your quick reference, I have created a dummy class called testClass (whether it is a handle class or not does not matter), with a property and function, and some dummy comments:
classdef testClass < handle
%%Test class
% More information about test class
properties
% Some value is stored in this property
testProperty
end
methods
function check()
%%This is a function that does so and so
% It also does something else..
disp('Hello');
end
end
end
The help text can be accessed by running:
>> help testClass
Test class
More information about test class
Reference page for testClass
>> help testClass.testProperty
Some value is stored in this property
>> help testClass.check
This is a function that does so and so
It also does something else..
Sincerely
Suraj Mankulangara
  1 comentario
Yasen P
Yasen P el 4 de Abr. de 2018
Thank you very much, this is quite helpful. I would like to further enquire if Matlab is capable of supporting the same functionality from the instance itself by pressing 'F1', or if I have to explicitly invoke the help command with the desired function, i.e.
instance = testClass;
help instance.check
can I achieve the same effect using the 'F1' key for fast access to the help section pressing while I am typing the "instance.check" into a script.

Iniciar sesión para comentar.

Categorías

Más información sobre Environment and Settings en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by