MatrixBerryCore
checkmultvar.m
Go to the documentation of this file.
1 function checkmultvar(typeSpec,nPlaceHolders,varargin)
2 import mxberry.core.throwerror;
3 import mxberry.core.check.lib.*;
4 %
5 if isempty(varargin)
6  reg=varargin;
7  nCallerStackStepsUp=1;
8 else
9  [reg,~,nCallerStackStepsUp]=mxberry.core.parseparext(varargin,...
10  {'nCallerStackStepsUp';1},'propRetMode','separate');
11 end
12 %
13 nVarArgs=length(reg);
14 if isempty(nPlaceHolders)
15  nPlaceHolders=nVarArgs;
16 end
17 %
18 if nVarArgs<nPlaceHolders
19  throwerror('wrongInput',['Values are expected to be provided for ',...
20  'each placeholder'],'nCallerStackStepsUp',1+nCallerStackStepsUp);
21 end
22 
23 isChar=ischar(typeSpec);
24 if isChar
25  for iVar=1:nPlaceHolders
26  assignIn(sprintf('x%d',iVar),reg{iVar});
27  end
28  isOk=eval(typeSpec);
29 else
30  isOk=feval(typeSpec,reg{1:nPlaceHolders});
31 end
32 
33 if ~isOk
34  %
35  if ischar(typeSpec)
36  checkName=typeSpec;
37  else
38  checkName=func2str(typeSpec);
39  end
40  defaultErrorMessage=...
41  ['%s is expected to comply with all of the following ',...
42  'conditions: %s'];
43  %
44  [~,~,varNameList,errorTag,errorMessage]=mxberry.core.parseparext(...
45  reg((nPlaceHolders+1):end),...
46  {...
47  'varNameList','errorTag','errorMessage';...
48  {},'wrongInput',defaultErrorMessage;...
50  },0);
51  %
52  nVarNames=length(varNameList);
53  if nVarNames>nPlaceHolders
54  throwerror('wrongInput',['Number of variable names exceeds ',...
55  'a number of place holders'],'nCallerStackStepsUp',...
56  1+nCallerStackStepsUp);
57  end
58  varNameList=[varNameList,cell(1,nPlaceHolders-nVarNames)];
59  %
60  for iVar=nVarNames+1:nPlaceHolders
61  varNameList{iVar}=inputname(2+iVar);
62  end
63  errorMessage=sprintf(errorMessage,...
64  mxberry.core.cell.cell2tablestr([],varNameList,','),checkName);
65  %
66  throwerror(errorTag,errorMessage,'nCallerStackStepsUp',...
67  1+nCallerStackStepsUp);
68 end
69 end
70 function assignIn(varName,varValue)
71 assignin('caller',varName,varValue);
72 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 checkmultvar(in typeSpec, in nPlaceHolders, in varargin)
CHECKMULTVAR checks a generic condition provided by typeSpec string in the following format: &#39;isnumer...
function assignIn(in varName, in varValue)
function iscellofstring(in inpArray)
function isstring(in inpArray)