Home > FMAToolbox > Helpers > isdmatrix.m

isdmatrix

PURPOSE ^

isdmatrix - Test if parameter is a matrix of doubles (>= 2 columns).

SYNOPSIS ^

function test = isdmatrix(x,varargin)

DESCRIPTION ^

isdmatrix - Test if parameter is a matrix of doubles (>= 2 columns).

  USAGE

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

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

  EXAMPLES

    % Test if x is a matrix of doubles
    isdmatrix(x)

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

    % Special test: test if x is a 3-line matrix of doubles
    isdmatrix(x,'#3')

    % Special test: test if x is a 2-column matrix of doubles
    isdmatrix(x,'@2')

  NOTE

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

  SEE ALSO

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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

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

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