Generates an error if the value of an input argument is not expected.
errmsg=apifun_checkoption(funname,var,varname,ivar,expectedopt)
a 1-by-1 matrix of strings, the name of the calling function.
a 1-by-1 matrix of valid Scilab data type, the variable
a 1-by-1 matrix of string, the name of the variable
a 1-by-1 matrix of floating point integers, the index of the input argument in the calling sequence
a n x 1 or 1 x n matrix of values, the available values for the variable #ivar
a 1-by-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 where an input argument has a limited number of possible values.
Caution : do not use apifun_checkrange in place of apifun_checkoption. The apifun_checkrange should be used to check that var is in a mathematical interval, which contains an infinite number of values. The apifun_checkoption should be used to check that var is in a mathematical set, which contains an finite number of values.
// The function takes a string argument, either "r" or "c". function myfunction(x) apifun_checkoption ( "myfunction",x,"x",1,["r" "c"] ) disp("This is the string:" + x) endfunction // Calling sequences which work myfunction ( "r" ) myfunction ( "c" ) // Calling sequences which generate an error myfunction ( "Scilab" ) | ![]() | ![]() |