MatrixBerryCore
checkcellofstr.m
Go to the documentation of this file.
1 function inpArray=checkcellofstr(inpArray,flagVec,varargin)
2 import mxberry.core.throwerror;
3 DEFAULT_IS_EMPTY_ALLOWED=false;
4 DEFAULT_IS_CHECKED_FOR_ROW=true;
5 %
6 [~,~,nCallerStackStepsUp]=mxberry.core.parseparext(...
7  varargin,...
8  {'nCallerStackStepsUp';1;...
9  'isscalar(x)&&isnumeric(x)&&isreal(x)'},0,...
10  'propRetMode','separate');
11 %
12 if nargin==1
13  flagVec=[DEFAULT_IS_EMPTY_ALLOWED,DEFAULT_IS_CHECKED_FOR_ROW];
14 elseif numel(flagVec)==1
15  flagVec=[flagVec,DEFAULT_IS_CHECKED_FOR_ROW];
16 end
17 isEmptyAllowed=flagVec(1);
18 isCheckedForBeingARow=flagVec(2);
19 %
20 if isCheckedForBeingARow
21  if ~(mxberry.core.isrow(inpArray)||isEmptyAllowed&&isempty(inpArray))
22  if ~isEmptyAllowed
23  throwerror('wrongInput',...
24  '%s is expected to be a row',inputname(1),...
25  'nCallerStackStepsUp',1+nCallerStackStepsUp);
26  else
27  throwerror('wrongInput',...
28  '%s is expected to be a row or empty cell',inputname(1),...
29  'nCallerStackStepsUp',1+nCallerStackStepsUp);
30  end
31  end
32 end
33 if ischar(inpArray)
34  inpArray={inpArray};
35 else
36  if ~iscellstr(inpArray)
37  throwerror('wrongInput',...
38  '%s is expected to be a cell array of strings',...
39  inputname(1),'nCallerStackStepsUp',1+nCallerStackStepsUp);
40  end
41  is2DVec=cellfun('ndims',inpArray)<=2;
42  if ~all(is2DVec)
43  throwerror('wrongInput',...
44  ['%s does have elements on positions %s with ',...
45  'dimensionality >2'],mat2str(find(~is2DVec)),...
46  'nCallerStackStepsUp',1+nCallerStackStepsUp);
47  end
48  isRowVec=cellfun('size',inpArray,1)==1;
49  if ~all(isRowVec)
50  throwerror('wrongInput',...
51  ['%s does have elements on positions %s that are ',...
52  ' matrices instead of rows'],mat2str(find(~isRowVec)),...
53  'nCallerStackStepsUp',1+nCallerStackStepsUp);
54  end
55 end
function throwerror(in msgTag, in varargin)
THROWERROR works similarly to built-in ERROR function in case when there is no output arguments but s...
function checkcellofstr(in inpArray, in flagVec, in varargin)
CHECKCELLOFSTR checks that input variable is either a char or cell of strings (char is converted to a...