<< apifun_checkoption Check content apifun_checkreal >>

Apifun >> Apifun > Check content > apifun_checkrange

apifun_checkrange

Check that the value is in a given range.

Calling Sequence

errmsg=apifun_checkrange(funname,var,varname,ivar,vmin,vmax)

Parameters

funname :

a 1-by-1 matrix of strings, the name of the calling function.

var :

a matrix of values, the variable

varname :

a 1-by-1 matrix of string, the name of the variable

ivar :

a 1-by-1 matrix of floating point integers, the index of the input argument in the calling sequence

vmin :

a 1-by-1 matrix of values, the minimum value for the variable #ivar

vmax :

a 1-by-1 matrix of values, the maximum value for the variable #ivar

errmsg :

a 1-by-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 where an input argument is expected to be greater or equal to a threshold. The error is generated if the condition and ( vmin <= var & var <= vmax ) is false. This function can be used for whatever variable type for which the comparison "<=" can be evaluated.

The variable var can be of type matrix of doubles ("constant"), integer (uint8, uint16, uint32, int8, int16, int32) or any other datatype for which the "<=" operator has been defined, including user-defined datatypes (for example, with tlists).

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.

Examples

// The function takes an argument x such that 0<= x <=1.
function y=myfunction(x)
apifun_checkrange ( "myfunction",x,"x",1,0,1 )
y = sqrt(1-x)
endfunction
// Calling sequences which work
myfunction ( [0.1 0.2 0.8] )
// Calling sequences which generate an error
// myfunction ( [-0.1 0.2 0.8] )
// myfunction ( [0.1 0.2 1.8] )

Authors


<< apifun_checkoption Check content apifun_checkreal >>