Home > FMAToolbox > Helpers > isdscalar.m

isdscalar

PURPOSE ^

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

SYNOPSIS ^

function test = isdscalar(x,varargin)

DESCRIPTION ^

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

  USAGE

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

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

  EXAMPLES

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

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

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

  NOTE

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

  SEE ALSO

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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

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

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