Home > atmlab > handy > rqre_in_range.m

rqre_in_range

PURPOSE ^

RQRE_IN_RANGE Require that a variable is inside a range

SYNOPSIS ^

function rqre_in_range( a, lowlim, highlim, nonstdname )

DESCRIPTION ^

 RQRE_IN_RANGE   Require that a variable is inside a range

    Issues an error if criterion not fulfilled.

    The check considers all values and *a* can be a matrix or a higher order
    tensor.

 FORMAT   rqre_in_range( a, [, lowlim, highlim, nonstdname ] )
        
 IN    a             Variable value. Can be of any numeric type.
 OPT   lowlim        It is required that a >= lowlim. Default is -Inf.
       highlim       It is required that a >= highlim. Default is Inf.
       nonstdname    Name of variable to use in error message. Default is
                     to use the function *inputname* to determine the
                     variable name.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

DOWNLOAD ^

rqre_in_range.m

SOURCE CODE ^

0001 % RQRE_IN_RANGE   Require that a variable is inside a range
0002 %
0003 %    Issues an error if criterion not fulfilled.
0004 %
0005 %    The check considers all values and *a* can be a matrix or a higher order
0006 %    tensor.
0007 %
0008 % FORMAT   rqre_in_range( a, [, lowlim, highlim, nonstdname ] )
0009 %
0010 % IN    a             Variable value. Can be of any numeric type.
0011 % OPT   lowlim        It is required that a >= lowlim. Default is -Inf.
0012 %       highlim       It is required that a >= highlim. Default is Inf.
0013 %       nonstdname    Name of variable to use in error message. Default is
0014 %                     to use the function *inputname* to determine the
0015 %                     variable name.
0016 
0017 % 2004-09-07   Created by Patrick Eriksson.
0018 
0019 
0020 function rqre_in_range( a, lowlim, highlim, nonstdname )
0021 
0022 if nargin < 2  ||  isempty( lowlim )
0023   lowlim = -Inf;
0024 end
0025 if nargin < 3  ||  isempty( highlim )
0026   highlim = Inf;  
0027 end
0028                                                                             %&%
0029 assert( isnumeric( a ) );                                                   %&%
0030 assert( istensor0( lowlim ) );                                              %&%
0031 assert( istensor0( highlim ) );                                             %&%
0032 
0033 if any( a(:) < lowlim )  ||  any( a(:) > highlim )
0034   if nargin < 4  ||  isempty(nonstdname)
0035     vname = sprintf( 'The variable *%s*', inputname(1) );
0036   else
0037     assert( ischar( nonstdname ) );
0038     vname = sprintf( '%s', nonstdname );
0039   end
0040   error(['atmlab:' mfilename ':invalid'], ...
0041       '%s is required to be in the range [%d,%d].', vname, lowlim, highlim );
0042 end
0043 
0044 end

Generated on Mon 15-Sep-2014 13:31:28 by m2html © 2005