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