Home > FMAToolbox > Helpers > isiscalar.m

isiscalar

PURPOSE ^

isiscalar - Test if parameter is a scalar (integer) satisfying an optional list of tests.

SYNOPSIS ^

function test = isiscalar(x,varargin)

DESCRIPTION ^

isiscalar - Test if parameter is a scalar (integer) satisfying an optional list of tests.

  USAGE

    test = isiscalar(x,test1,test2,...)

    x              parameter to test
    test1...       optional list of additional tests

  EXAMPLES

    % Test if x is a scalar (double)
    isiscalar(x)

    % Test if x is a strictly positive scalar (double)
    isiscalar(x,'>0')

    % Test if x is a scalar (double) included in [2,3]
    isiscalar(x,'>=2','<=3')

  NOTE

    The tests ignore NaN, e.g. isiscalar(nan), isiscalar(nan,'>0') and isiscalar(nan,'<=0')
    all return 1.

  SEE ALSO

    See also isdmatrix, isdvector, isdscalar, isimatrix, isivector, isastring,
    islscalar, islvector, islmatrix.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 %isiscalar - Test if parameter is a scalar (integer) satisfying an optional list of tests.
0002 %
0003 %  USAGE
0004 %
0005 %    test = isiscalar(x,test1,test2,...)
0006 %
0007 %    x              parameter to test
0008 %    test1...       optional list of additional tests
0009 %
0010 %  EXAMPLES
0011 %
0012 %    % Test if x is a scalar (double)
0013 %    isiscalar(x)
0014 %
0015 %    % Test if x is a strictly positive scalar (double)
0016 %    isiscalar(x,'>0')
0017 %
0018 %    % Test if x is a scalar (double) included in [2,3]
0019 %    isiscalar(x,'>=2','<=3')
0020 %
0021 %  NOTE
0022 %
0023 %    The tests ignore NaN, e.g. isiscalar(nan), isiscalar(nan,'>0') and isiscalar(nan,'<=0')
0024 %    all return 1.
0025 %
0026 %  SEE ALSO
0027 %
0028 %    See also isdmatrix, isdvector, isdscalar, isimatrix, isivector, isastring,
0029 %    islscalar, islvector, islmatrix.
0030 %
0031 
0032 
0033 % Copyright (C) 2010 by Michaƫl Zugaro
0034 %
0035 % This program is free software; you can redistribute it and/or modify
0036 % it under the terms of the GNU General Public License as published by
0037 % the Free Software Foundation; either version 3 of the License, or
0038 % (at your option) any later version.
0039 
0040 function test = isiscalar(x,varargin)
0041 
0042 % Check number of parameters
0043 if nargin < 1,
0044   error('Incorrect number of parameters (type ''help <a href="matlab:help isiscalar">isiscalar</a>'' for details).');
0045 end
0046 
0047 % Test: double, scalar
0048 test = isa(x,'double') & isscalar(x);
0049 if ~test, return; end
0050 
0051 % Test: integers?
0052 test = test & round(x)==x;
0053 
0054 % Optional tests
0055 for i = 1:length(varargin),
0056     try
0057         if ~eval(['x' varargin{i} ';']), test = false; return; end
0058     catch err
0059         error(['Incorrect test ''' varargin{i} ''' (type ''help <a href="matlab:help isiscalar">isiscalar</a>'' for details).']);
0060     end
0061 end

Generated on Fri 16-Mar-2018 13:00:20 by m2html © 2005