Error using nargin You can only call nargin/nargout from within a MATLAB function.

조회 수: 33 (최근 30일)
if nargin &&ischar(varargin{1})

답변 (1개)

Walter Roberson
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
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)
ans = 1
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
Error using nargin
You can only call nargin/nargout from within a MATLAB function.
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 CenterFile Exchange에서 Argument Definitions에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by