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

53 visualizaciones (últimos 30 días)
if nargin &&ischar(varargin{1})

Respuestas (1)

Walter Roberson
Walter Roberson el 9 de Mzo. de 2021
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 comentario
Steven Lord
Steven Lord el 9 de Mzo. de 2021
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.

Iniciar sesión para comentar.

Categorías

Más información sobre Argument Definitions en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by