MatrixBerryCore
checkvar.m
Go to the documentation of this file.
1 function checkvar(x,typeSpec,varargin)
2 import mxberry.core.throwerror;
3 import mxberry.core.check.lib.*;
4 %
5 isChar=ischar(typeSpec);
6 if isChar&&~eval(typeSpec)||~isChar&&~builtin('feval',typeSpec,x)
7  %
8  if ischar(typeSpec)
9  checkName=typeSpec;
10  else
11  checkName=func2str(typeSpec);
12  end
13  %
14  defaultErrorMessage=['%s is expected to comply with all of ',...
15  'the following conditions: %s'];
16  %
17  [reg,~,errorTag,errorMessage,nCallerStackStepsUp]=mxberry.core.parseparext(...
18  varargin,...
19  {'errorTag','errorMessage','nCallerStackStepsUp';...
20  'wrongInput',defaultErrorMessage,1;...
21  @isstring,@isstring,...
22  'isscalar(x)&&isnumeric(x)&&isreal(x)'},[0,1],...
23  'regDefList',{inputname(1)},...
24  'regCheckList',{@isstring});
25  varName=reg{1};
26  errorMessage=sprintf(errorMessage,varName,checkName);
27  %
28  throwerror(errorTag,errorMessage,...
29  'nCallerStackStepsUp',1+nCallerStackStepsUp);
30 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 checkvar(in x, in typeSpec, in varargin)
CHECKVAR checks a generic condition provided by typeSpec string in the following format: 'isnumeric(x...
function isstring(in inpArray)