Home > FMAToolbox > Helpers > isdvector.m

isdvector

PURPOSE ^

isdvector - Test if parameter is a vector of doubles satisfying an optional list of tests.

SYNOPSIS ^

function test = isdvector(x,varargin)

DESCRIPTION ^

isdvector - Test if parameter is a vector of doubles satisfying an optional list of tests.

  USAGE

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

    x              parameter to test
    test1...       optional list of additional tests (see examples below)

  EXAMPLES

    % Test if x is a vector of doubles
    isdvector(x)

    % Test if x is a vector of strictly positive doubles
    isdvector(x,'>0')

    % Test if x is a vector of doubles included in [2,3]
    isdvector(x,'>=2','<=3')

    % Special test: test if x is a vector of doubles of length 3
    isdvector(x,'#3')

    % Special test: test if x is a vector of strictly ordered doubles
    isdvector(x,'>')

  NOTE

    The tests ignore NaNs, e.g. isdvector([5e-3 nan]), isdvector([1.7 nan 3],'>0') and
    isdvector([nan -7.4],'<=0') all return 1.

  SEE ALSO

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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

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

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