Home > FMAToolbox > Helpers > isimatrix.m

isimatrix

PURPOSE ^

isimatrix - Test if parameter is a matrix of integers (>= 2 columns).

SYNOPSIS ^

function test = isimatrix(x,varargin)

DESCRIPTION ^

isimatrix - Test if parameter is a matrix of integers (>= 2 columns).

  USAGE

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

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

  EXAMPLES

    % Test if x is a matrix of integers
    isimatrix(x)

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

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

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

  NOTE

    The tests ignore NaNs, e.g. isimatrix([500 nan;4 79]), isimatrix([1 nan 3],'>0') and
    isimatrix([nan -7;nan nan;-2 -5],'<=0') all return 1.

  SEE ALSO

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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 %isimatrix - Test if parameter is a matrix of integers (>= 2 columns).
0002 %
0003 %  USAGE
0004 %
0005 %    test = isimatrix(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 integers
0013 %    isimatrix(x)
0014 %
0015 %    % Test if x is a matrix of strictly positive integers
0016 %    isimatrix(x,'>0')
0017 %
0018 %    % Special test: test if x is a 3-line matrix of integers
0019 %    isimatrix(x,'#3')
0020 %
0021 %    % Special test: test if x is a 2-column matrix of integers
0022 %    isimatrix(x,'@2')
0023 %
0024 %  NOTE
0025 %
0026 %    The tests ignore NaNs, e.g. isimatrix([500 nan;4 79]), isimatrix([1 nan 3],'>0') and
0027 %    isimatrix([nan -7;nan nan;-2 -5],'<=0') all return 1.
0028 %
0029 %  SEE ALSO
0030 %
0031 %    See also isdmatrix, isdvector, isdscalar, 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 = isimatrix(x,varargin)
0043 
0044 % Check number of parameters
0045 if nargin < 1,
0046   error('Incorrect number of parameters (type ''help <a href="matlab:help isimatrix">isimatrix</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 % Test: integers?
0053 test = test & all(round(x(:))==x(:));
0054 
0055 % Optional tests
0056 for i = 1:length(varargin),
0057     try
0058         if varargin{i}(1) == '#',
0059             if size(x,1) ~= str2num(varargin{i}(2:end)), test = false; return; end
0060         elseif varargin{i}(1) == '@',
0061             if size(x,2) ~= str2num(varargin{i}(2:end)), test = false; return; end
0062         elseif ~eval(['all(x(~isnan(x))' varargin{i} ');']), test = false; return; end
0063     catch err
0064         error(['Incorrect test ''' varargin{i} ''' (type ''help <a href="matlab:help isimatrix">isimatrix</a>'' for details).']);
0065     end
0066 end

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