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

 Akzeptierte Antwort

James Tursa
James Tursa am 7 Mär. 2017
Bearbeitet: James Tursa am 7 Mär. 2017

2 Stimmen

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 Kommentar

ghida hayajneh
ghida hayajneh am 7 Mär. 2017
why i use this nargin if i dont need it in my code and not passed in E.G

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Argument Definitions finden Sie in Hilfe-Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by