MATLAB Documentation for OOP
(For reference by students)


 

NARGIN
Definition Number of function input arguments. Inside the body of a user-defined function, NARGIN returns the number of input arguments that were used to call the function.
 
Example
function acct = BankAccount(data)
if nargin == 0                        
   acct.balance = 0;
   acct = class(acct,'BankAccount');
elseif isa(data, 'BankAccount')          
   acct = data;
else
   acct.balance = data;
   acct = class(acct,'BankAccount');
end
 

In this example, if the number of input arguments was 0, then it creates a new field called balance in the class BankAccount


Got comments\feedback\suggestions\complaints\anything whatsoever? Shoot the webmaster an email!

Website created & maintained by Shardul Bhatia and Wen Eu Cheah