2008年11月25日星期二

有趣的Matlab注释-自己写m文件函数帮助的技巧

每当我们help一个函数的时候,我们可以看到,Matlab会在最后加上See also,其实,自己写的m文件帮助也可以加上See also 后面带有链接这种功能的东西
如果在函数的第二行开始写注释,就可以实现用help function命令显示帮助信息的功能,这可能大家都知道了,就不多说了,关键是如何实现See also
See also 的具体实现不知道Matlab是怎么做到的,但是,只要我们注意一下写的格式,就可以写出See also来:
在See also FUNCTIONNAME的后面,一般是英文句号,其后一定要有空格,并且See also 必须这样写,不可以写成see also 或者别的什么,最重要的,See also 后面的函数名字要全部大写
function testHelp
%testHelp tests help
% You can get help from it
% See also TESTHELP.

出来的效果如下:
testHelp tests help
You can get help from it
See also testhelp.

可以看到,上面的testhelp被自动小写,而且加了链接
如果有一个字母没有大写,比如第一个t:

function testHelp
%testHelp tests help
% You can get help from it
% See also tESTHELP.


效果如下:
testHelp tests help
You can get help from it
See also testhelp.

可以看到,除了t之外,后面的esthelp被链接了
如果英文的句号后面没有空格:
function testHelp
%testHelp tests help
% You can get help from it
% See also TESTHELP.

效果如下:
testHelp tests help
You can get help from it
See also

这下一点也显示不出来了,很有意思,如果有多个函数需要see also,直接打逗号再写就可以了。

没有评论: