Home > FMAToolbox > Helpers > islmatrix.m

islmatrix

PURPOSE ^

islmatrix - Test if parameter is a logical matrix (>= 2 columns).

SYNOPSIS ^

function test = islmatrix(x,varargin)

DESCRIPTION ^

islmatrix - Test if parameter is a logical matrix (>= 2 columns).

  USAGE

    test = islmatrix(x)

    x              parameter to test

  EXAMPLES

    % Test if x is a logical matrix
    islmatrix(x)

    % Special test: test if x is a 3-line logical matrix
    islmatrix(x,'#3')

    % Special test: test if x is a 2-column logical matrix
    islmatrix(x,'@2')

  NOTE

    To be considered logical, the matrix should contain only values 0 and 1, but it
    does not need to actually be of class 'logical' (class(x) could be e.g. 'double').

  SEE ALSO

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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 %islmatrix - Test if parameter is a logical matrix (>= 2 columns).
0002 %
0003 %  USAGE
0004 %
0005 %    test = islmatrix(x)
0006 %
0007 %    x              parameter to test
0008 %
0009 %  EXAMPLES
0010 %
0011 %    % Test if x is a logical matrix
0012 %    islmatrix(x)
0013 %
0014 %    % Special test: test if x is a 3-line logical matrix
0015 %    islmatrix(x,'#3')
0016 %
0017 %    % Special test: test if x is a 2-column logical matrix
0018 %    islmatrix(x,'@2')
0019 %
0020 %  NOTE
0021 %
0022 %    To be considered logical, the matrix should contain only values 0 and 1, but it
0023 %    does not need to actually be of class 'logical' (class(x) could be e.g. 'double').
0024 %
0025 %  SEE ALSO
0026 %
0027 %    See also islscalar, islvector, isdmatrix, isdvector, isdscalar, isivector, isiscalar,
0028 %    isastring.
0029 %
0030 
0031 % Copyright (C) 2010-2015 by Michaƫl Zugaro
0032 %
0033 % This program is free software; you can redistribute it and/or modify
0034 % it under the terms of the GNU General Public License as published by
0035 % the Free Software Foundation; either version 3 of the License, or
0036 % (at your option) any later version.
0037 
0038 function test = islmatrix(x,varargin)
0039 
0040 % Check number of parameters
0041 if nargin < 1,
0042   error('Incorrect number of parameters (type ''help <a href="matlab:help islmatrix">islmatrix</a>'' for details).');
0043 end
0044 
0045 % Test: logical, two dimensions, two or more columns?
0046 test = islogical(x) & length(size(x)) == 2 & size(x,2) >= 2;
0047 
0048 % Optional tests
0049 for i = 1:length(varargin),
0050     try
0051         if varargin{i}(1) == '#',
0052             if size(x,1) ~= str2num(varargin{i}(2:end)), test = false; return; end
0053         elseif varargin{i}(1) == '@',
0054             if size(x,2) ~= str2num(varargin{i}(2:end)), test = false; return; end
0055         end
0056     catch err
0057         error(['Incorrect test ''' varargin{i} ''' (type ''help <a href="matlab:help isdmatrix">islmatrix</a>'' for details).']);
0058     end
0059 end
0060 
0061 
0062 function test = islogical(x)
0063 
0064 test = builtin('islogical',x) | all(x(:)==0|x(:)==1);

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