2010-10-01 119 views
19

我找不到可用於爲您自己的MATLAB函數編寫幫助的格式。很少有信息可用in official documentationMATLAB m文件幫助格式化

您是否知道可以通過幫助瀏覽器(不帶幫助功能)看到的其他任何格式?就像內置函數一樣。如何格式標題(如語法,說明,示例)?子彈,桌子可能嗎? 或者可能它應該是一個單獨的文件?

我試過文字標記用於發佈和HTML,沒有工作。

我發現只有一件有趣的事情。如果你的函數包含混合的情況下,像testHelpFunction,它的名字將被突出顯示:

alt text

不突出,如果它只是testhelpfunction

還有其他想法嗎?

UPDATE

這裏是大量的文檔我創建自己的幫助文件中找到:

Providing Your Own Help and Demos
(與Web歸檔鏈接替換死鏈接)


(死鏈接刪除)


再次更新:

+0

您添加第二個環節正是我正要建議。那裏非常有用的東西。 – gnovice 2010-10-01 16:52:22

+0

你應該把你的UPDATE作爲答案,並接受它! – 2010-10-01 16:57:57

+1

@Alex,我打算收集關於m文件格式的信息。創建單獨的文檔只是一個側面問題。 – yuk 2010-10-01 18:42:35

回答

13

嘗試在官方文檔中的其他部分。它更徹底。 MATLAB>用戶手冊>桌面工具和開發環境>自定義幫助和演示>提供您自己的幫助和演示。這描述了簡單的幫助文本和生成單獨的HTML幫助文件。

這裏是我選擇的幫助文本格式,並發現有用。

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'); 
  • 函數簽名後的第一行被稱爲「H1線」。它需要只是一行,因此它可以由contentrpt()正確拾取,它可以從函數中的幫助文本自動生成Contents.m文件。
  • H1行中的函數名稱全部爲大寫,無論實際大寫在簽名中的函數名稱
  • 「另請參見」的情況。我不確定哪些案件都有效;這個確實如此。
  • 「另請參閱:」後的函數名稱全部大寫。方法名稱是合格的;我認爲與當前方法在相同類中的方法名稱可能是不合格的。

H1行與「Examples:」之間的所有內容都是我發現可讀的傳統格式; help()不會專門處理它。

您可以在幫助中使用有限形式的超鏈接。特別是,您可以使用超鏈接來調用任意的Matlab命令,並通過調用help()指向helptext的其他部分。你可以用它來指向任何函數; 「function> subfunction」只是在help()調用中尋址子函數的語法。不幸的是,由於您需要在這些超鏈接中放置「幫助」或「文檔」,它只能以一種或另一種表示形式工作。如果有一個直接的helptext超鏈接表單,會更好。

+0

我決定接受這個答案,作爲m文件幫助格式化功能的最完整摘要。謝謝,安德魯。我非常感謝其他答案。 – yuk 2010-10-08 15:36:10

+0

你提到的幫助部分似乎在最新版本中沒有了? – 2014-10-28 14:56:49

4

我想,有一些(見例子),但我從來沒有發現相應的文檔。我經常有這樣的塊:

% ... 
% 
% See also: 
% this_other_function() 
% 
% <author> 

而且See also部分被格式化爲標題,但如果你用別的東西代替See also,這是行不通的。如果有人發現這些支持的標題的列表,請在這裏鏈接到它!

編輯

我最近來了解MATLAB的內置發佈系統。看起來MATLAB評論支持某種形式的標記,與Markdown的語法(與SO本身使用的語法不同)不支持LaTeX等式和所有的語法。

「Loren在MATLAB的藝術」上有一篇關於發佈和標記的文章short introduction。有關完整參考資料,請參見Mathworks網站上的Making Up MATLAB Comments for Publishing

當您的代碼準備好後,您可以使用publish() function將結果導出爲HTML/PDF/XML等。我使用以下片段導出我的文件:

% Other formats are supported, refer to documentation. 
options.format = 'html'; 

    % I don't evaluate the code, especially for functions that require arguments. 
    % However, if providing a demo, turning this on is a fantastic way to embed 
    % figures in the resulting document. 
options.evalCode = false; 

    % You can run this in a loop over files in the currrent directory if desired. 
publish('script.m', options); 
+0

謝謝。很棒的發現+1。有趣的是,「另請參閱」部分將在幫助瀏覽器幫助的最後。現有的功能將鏈接到其幫助頁面。 – yuk 2010-10-01 15:54:04

4

我認爲幫助格式化中最重要的方面是有幫助,並且格式是一致的,以便您(以及與您一起工作的人)不會浪費時間找到如何查找信息。請注意,對於OOP,使用'help'方法調用doc(class(obj))是非常有用的,因爲您無法輕鬆地從類的實例化中獲取幫助。

爲了幫助我保持一致(並確保我不會忘記東西),我在文件交換中創建了一個automatic function template

這裏是最小的頭

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 
%