将参数发送到“帮助”功能

时间:2012-06-19 12:35:28

标签: function matlab arguments

如何向help函数发送参数?

我希望有这样的事情:

function intro(funcname)
  disp('This is an introduction to the function you chose. See the help below:')
  help funcname
end

我可以在其中显示函数的帮助文本,该名称作为函数中的参数。但是,当MatLab只搜索funcname作为函数名而不是变量值时,上述方法不起作用。

1 个答案:

答案 0 :(得分:3)

简而言之:是的,您可以使用help的函数形式执行此操作:

  x = 'mean';
  help(x);

在你的例子中:

function intro(funcname)
  disp('This is an introduction to the function you chose. See the help below:')
  help(funcname);
end

<强>说明: 您正在使用的表单

help xxx

只是一个捷径:

 help('xxx');

如果你有多个以空格分隔的参数(感谢@Amro就此而言),它就像发送多个参数一样: 例如:

mcc -m fileNames

等于

mcc('-m','fileNames');

作为代表我的观点的旁注,我想补充一点,一般来说,第二种形式是首选,除非你编写一个快速而肮脏的代码。