2

我只是在编写一个 Matlab 函数,并想将我所拥有的内容复制并粘贴到一个交互式会话中。其中一些是nargin语句(例如if nargin < 1; a = 0; end;),事实证明nargin在我的工作区中具有值 11005,而我没有分配它。有谁知道这是什么,它是否用于任何事情(函数之外)以及将其设置为零是否有任何问题?

4

1 回答 1

3

When used within a function, nargin gives the number of parameters passed to that function. Used with a string argument fn it is an in-built function, which returns the number of parameters taken by function fn. You should not call it without a parameter from the workspace:

nargin returns the number of input arguments passed in the call to the currently executing function. Use this nargin syntax only in the body of a function.

You can, but you should avoid assigning a value to nargin, since it will then loose the second semantics:

nargin('sparse')

ans =

 6

nargin = 0;
nargin('sparse')
Index exceeds matrix dimensions.
于 2012-11-27T13:47:16.287 回答