if nargin < 5, s_verbose = 'on'; end
if nargin < 4, s_interactive = 'off'; end
if nargin < 3, lastEig = size(vectors, 1); end
if nargin < 2, firstEig = 1; end

 Réponse acceptée

James Tursa
James Tursa le 7 Mar 2017
Modifié(e) : James Tursa le 7 Mar 2017

2 votes

You don't show the entire code, but my guess would be this is inside a function that looks something like this:
function outputs = myfunction(vectors,firstEig,lastEig,s_interactive,s_verbose)
if nargin < 5, s_verbose = 'on'; end
if nargin < 4, s_interactive = 'off'; end
if nargin < 3, lastEig = size(vectors, 1); end
if nargin < 2, firstEig = 1; end
:
etc
nargin is a function that returns the actual number of arguments passed into a function. So the code in question is simply assigning default values for those arguments that were not actually passed in. E.g., if the caller only passed in four arguments and did not pass in that last s_verbose argument, then the above code would assign the value 'on' to the s_verbose local variable.

1 commentaire

ghida hayajneh
ghida hayajneh le 7 Mar 2017
why i use this nargin if i dont need it in my code and not passed in E.G

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Argument Definitions dans Centre d'aide et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by