Generates an error if the number of RHS is not in given set.
errmsg = fmincon_checkrhs ( funname , rhs , rhsset )
a 1 x 1 matrix of strings, the name of the calling function.
a 1 x 1 matrix of floating point integers, the actual number of input arguments
a 1 x n or n x 1 matrix of floating point integers, the authorized number of input arguments
a 1 x 1 matrix of strings, the error message. If there was no error, the error message is the empty matrix.
This function is designed to be used to design functions with variable number of input arguments. Notice that it is useless to call this function if the function definition does not use the varargin statement. Last update : 29/07/2010.
// The function takes 2/3 input arguments and 1 output arguments function y=myfunction(varargin) [lhs, rhs] = argn() fmincon_checkrhs ( "myfunction" , rhs , 2:3 ) fmincon_checklhs ( "myfunction" , lhs , 1 ) x1 = varargin(1) x2 = varargin(2) if ( rhs >= 3 ) then x3 = varargin(3) else x3 = 2 end y = x1 + x2 + x3 endfunction // Calling sequences which work y = myfunction ( 1 , 2 ) y = myfunction ( 1 , 2 , 3 ) // Calling sequences which generate an error y = myfunction ( 1 ) y = myfunction ( 1 , 2 , 3 , 4 ) // The function takes 2 or 4 input arguments, but not 3 function y=myfunction(varargin) [lhs, rhs] = argn() fmincon_checkrhs ( "myfunction" , rhs , [2 4] ) fmincon_checklhs ( "myfunction" , lhs , 1 ) x1 = varargin(1) x2 = varargin(2) if ( rhs >= 3 ) then x3 = varargin(3) x4 = varargin(4) else x3 = 2 x4 = 3 end y = x1 + x2 + x3 + x4 endfunction // Calling sequences which work y = myfunction ( 1 , 2 ) y = myfunction ( 1 , 2 , 3 , 4 ) // Calling sequences which generate an error y = myfunction ( 1 ) y = myfunction ( 1 , 2 , 3 ) y = myfunction ( 1 , 2 , 3 , 4, 5 )