Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MATLAB m-file help formatting

Tags:

I could not find what formatting available to write help for your own MATLAB function. Very little information is available in official documentation.

Do you know about any other formatting that can be visible with Help Browser (not with help function)? As it is for built-in functions. How to format headings (like Syntax, Description, Examples)? Are bullets, tables possible? Or may be it should be a separate file?

I've tried text markup as used for PUBLISH and HTML, didn't work.

I found only one interesting thing. If your function contains mixed case, like testHelpFunction, its name will be highlighted:

alt text

No highlighting if it's just testhelpfunction.

Any other thoughts?

UPDATE

Here is extensive documentation I found on creating your own help files:

Providing Your Own Help and Demos
(Dead link replaced with web archive link)


(Dead link removed)


Updated again:

  • Add Help for Your Program
  • Display Custom Documentation
like image 905
yuk Avatar asked Oct 01 '10 15:10

yuk


People also ask

What does %G do in MATLAB?

For the %g operator, the precision indicates the number of significant digits to display. For the %f , %e , and %E operators, the precision indicates how many digits to display to the right of the decimal point. Display numbers to different precisions using the precision field.

How do I fix an indentation in MATLAB?

Direct link to this answerType control-a (to select all code), then control-i (to fix the indenting).

What is %f and %S in MATLAB?

%s represents character vector(containing letters) and %f represents fixed point notation(containining numbers). In your case you want to print letters so if you use %f formatspec you won't get the desired result.


2 Answers

Try this other section in the official documentation. It's more thorough. MATLAB > User's Guide > Desktop Tools and Development Environment > Customizing Help and Demos > Providing Your Own Help and Demos. This describes both simple helptext and generating separate HTML help files.

Here's the helptext formatting I've picked up on and found useful.

function foo(x,y,z) %FOO One-line description goes here % % foo(x,y,z) % % Multi-line paragraphs of descriptive text go here. It's fine for them to % span lines. It's treated as preformatted text; help() and doc() will not % re-wrap lines. In the editor, you can highlight paragraphs, right-click, % and choose "Wrap selected comments" to re-flow the text. % % More detailed help is in the <a href="matlab: help foo>extended_help">extended help</a>. % It's broken out like this so you can keep the main "help foo" text on  % a single screen, and then break out obscure parts to separate sections. % % Examples: % foo(1,2,3) % % See also: % BAR % SOMECLASS/SOMEMETHOD  disp(x+y+z);  function extended_help %EXTENDED_HELP Some additional technical details and examples % % Here is where you would put additional examples, technical discussions, % documentation on obscure features and options, and so on.  error('This is a placeholder function just for helptext'); 
  • The first line after the function signature is called the "H1 line". It needs to be just one line so it is properly picked up by contentsrpt(), which can autogenerate a Contents.m file from the helptext in your functions
  • The function name in the H1 line is all caps, regardless of actual capitalization of the function name in the signature
  • Case matters for the "See also". I'm not sure which all cases work; this one does for sure.
  • Function names after "See also:" are all caps. Method names are qualified; I think names of methods in the same class as the current method can be unqualified.

Everything between the H1 line and "Examples:" is just a conventional formatting that I find readable; help() doesn't treat it specially.

You can use a limited form of hyperlinks in help. In particular, you can use hyperlinks to invoke arbitrary Matlab commands, and point to other sections of helptext by having it invoke help(). You can use this to point to any function; "function>subfunction" is just the syntax for addressing subfunctions in help() calls. Unfortunately, since you need to put either "help" or "doc" in those hyperlinks, it only works in one or the other presentation form. It would be nicer if there were a direct helptext hyperlink form.

like image 111
Andrew Janke Avatar answered Oct 18 '22 15:10

Andrew Janke


I think the most important aspect in help formatting is that there is a help at all, and that your formatting is consistent, so that you (and people working with you) don't waste time finding out how to look for the information. Note that for OOP, it is useful to have a superclass with a 'help'-method that calls doc(class(obj)), since you cannot easily access the help from an instantiation of your class

To help me be consistent (and to make sure I don't forget stuff), I have created an automatic function template on the file exchange.

Here's the minimal header

function testhelp %TESTHELP is an example (this is the H1 line) % % SYNOPSIS: a=testhelp(b,c) % % INPUT b: some input parameter %       c: (opt) some optional input parameter. Default: [] % % OUTPUT a: some output parameter % % REMARKS This is just an example, it won't run % % SEE ALSO testHelpFunction % % created with MATLAB ver.: 7.11.0.584 (R2010b) on Mac OS X  Version: 10.6.4 Build: 10F569  % % created by: Jonas % DATE: 01-Oct-2010 % 
like image 40
Jonas Avatar answered Oct 18 '22 13:10

Jonas