2

如何向help函数发送参数?

我希望有这样的东西:

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

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

4

1 回答 1

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');

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

于 2012-06-19T12:38:16.280 回答