Error using nargin You can only call nargin/nargout from within a MATLAB function.
33 次查看(过去 30 天)
显示 更早的评论
if nargin &&ischar(varargin{1})
0 个评论
回答(1 个)
Walter Roberson
2021-3-9
nargin cannot be used at the command line, and it cannot be used in a script file or Live Script (except inside a function defined within a script.)
Exception to those: it can be used in the definition of an anonymous function, and those can be inside a script or command line.
1 个评论
Steven Lord
2021-3-9
nargin can only be called from the MATLAB prompt if you call it with an input argument. If you do this will return the number of input arguments the function handle that you pass into it can accept.
nargin(@sin)
This says the function handle @sin accepts one input argument.
When called without an input it returns the number of input arguments that were passed in when the function in which nargin was called was called. Since there is no "function in which nargin was called" at the MATLAB prompt, that throws an error.
nargin
That error message is mostly correct (it shows the 0-input calls) but perhaps a little misleading. I'll note that to the development team.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Argument Definitions 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!