diff options
author | Harpreet | 2016-09-03 00:36:51 +0530 |
---|---|---|
committer | Harpreet | 2016-09-03 00:36:51 +0530 |
commit | a0d9443af147e949c1e6a01ac24749d12593ec5b (patch) | |
tree | 1a1955c5482ae608fd7f618b06f4ecc6a0d39a23 /macros/Checkrhs.sci | |
parent | 4b64cf486f5c999fd8167758cae27839f3b50848 (diff) | |
download | FOSSEE-Optim-toolbox-development-a0d9443af147e949c1e6a01ac24749d12593ec5b.tar.gz FOSSEE-Optim-toolbox-development-a0d9443af147e949c1e6a01ac24749d12593ec5b.tar.bz2 FOSSEE-Optim-toolbox-development-a0d9443af147e949c1e6a01ac24749d12593ec5b.zip |
cbcintlinprog added
Diffstat (limited to 'macros/Checkrhs.sci')
-rw-r--r-- | macros/Checkrhs.sci | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/macros/Checkrhs.sci b/macros/Checkrhs.sci new file mode 100644 index 0000000..6b5cf5b --- /dev/null +++ b/macros/Checkrhs.sci @@ -0,0 +1,102 @@ +// Copyright (C) 2010 - DIGITEO - Michael Baudin +// +// This file must be used under the terms of the GNU LGPL license. + +function errmsg = Checkrhs ( funname , rhs , rhsset ) + // Generates an error if the number of RHS is not in given set. + // + // Calling Sequence + // errmsg = Checkrhs ( funname , rhs , rhsset ) + // + // Parameters + // funname : a 1 x 1 matrix of strings, the name of the calling function. + // rhs : a 1 x 1 matrix of floating point integers, the actual number of input arguments + // rhsset : a 1 x n or n x 1 matrix of floating point integers, the authorized number of input arguments + // errmsg : a 1 x 1 matrix of strings, the error message. If there was no error, the error message is the empty matrix. + // + // Description + // 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 : 05/08/2010. + // Last update : 29/07/2010. + // + // Examples + // // The function takes 2/3 input arguments and 1 output arguments + // function y = myfunction ( varargin ) + // [lhs, rhs] = argn() + // Checkrhs ( "myfunction" , rhs , 2:3 ) + // 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() + // Checkrhs ( "myfunction" , rhs , [2 4] ) + // 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 ) + // + // // The function takes 2 input arguments and 0/1 output arguments. + // // Notice that if the checkrhs function is not called, + // // the variable x2 might be used from the user's context, + // // that is, if the caller has defined the variable x2, it + // // is used in the callee. + // // Here, we want to avoid this. + // function y = myfunction ( x1 , x2 ) + // [lhs, rhs] = argn() + // Checkrhs ( "myfunction" , rhs , 2 ) + // Checklhs ( "myfunction" , lhs , [0 1] ) + // y = x1 + x2 + // endfunction + // // Calling sequences which work + // y = myfunction ( 1 , 2 ) + // // Calling sequences which generate an error + // y = myfunction ( 1 ) + // y = myfunction ( 1 , 2 , 3 ) + // + // Authors + // Michael Baudin - 2010 - DIGITEO + // + + errmsg = [] + if ( and(rhs <> rhsset) ) then + rhsstr = strcat(string(rhsset)," ") + errmsg = msprintf(gettext("%s: Unexpected number of input arguments : %d provided while the number of expected input arguments should be in the set [%s]."), funname , rhs , rhsstr ); + error(errmsg) + end +endfunction + + + |