1 function [reg, prop]=
parseparams(args,propNameList,nRegExpected,nPropExpected)
4 isUsePropNamesUsed=
false;
6 if ~(isempty(propNameList)&&isnumeric(propNameList))
7 if ischar(propNameList)
8 propNameList={propNameList};
10 if ~iscellstr(propNameList)
12 'propNameList is expected to be a cell array of strings');
14 propNameList=cellfun(@lower,propNameList,
'UniformOutput',
false);
15 isUsePropNamesUsed=
true;
19 if ~isUsePropNamesUsed
20 isPropCandidateVec=
false(size(args));
21 isPropCandidateVec(length(args)-1:-2:1)=
true;
23 isPropCandidateVec=
true(size(args));
24 if numel(isPropCandidateVec)>0
25 isPropCandidateVec(end)=
false;
29 isPropCandidateVec=isPropCandidateVec&cellfun(
'isclass',args,
'char');
30 if any(isPropCandidateVec)
31 isPropCandidateVec=isPropCandidateVec&cellfun(
'ndims',args)==2&...
32 cellfun(
'size',args,1)==1;
36 cellfun(@lower,args(isPropCandidateVec),
'UniformOutput',
false)...
38 isPropCandidateVec(isPropCandidateVec)=isPropSubVec;
39 if ~isempty(isPropCandidateVec)&&...
40 any(isPropCandidateVec&isPropCandidateVec([end,1:end-1]))
41 throwerror('wrongParamList','property list is badly formed');
44 indPropVec=find(isPropCandidateVec);
45 if isempty(indPropVec)
49 prop=args(sort([indPropVec,indPropVec+1]));
50 propResNameList=args(isPropCandidateVec);
51 [isUnique,propUResNameList]=
mxberry.
core.isunique(propResNameList);
53 nResProps=length(propResNameList);
54 [~,indThereVec]=
ismember(propResNameList,propUResNameList);
55 nResPropSpecVec=accumarray(indThereVec.
',ones(nResProps,1)); 56 isPropDupVec=nResPropSpecVec>1; 57 dupPropListStr=mxberry.core.cell.cellstr2expression(... 58 propUResNameList(isPropDupVec)); 59 throwerror('wrongInput:duplicatePropertiesSpec
',... 60 sprintf('properties %s are specified more than once
',... 63 isPropCandidateVec(indPropVec+1)=true; 64 reg=args(~isPropCandidateVec); 67 if isnumeric(nRegExpected) 68 if isempty(nRegExpected) 70 elseif numel(nRegExpected)==1&&... 71 nRegExpected>=0&&fix(nRegExpected)==nRegExpected 72 if numel(reg)~=nRegExpected 73 throwerror('wrongParamList
',... 74 ['a number of extracted regular parameters (%d) does
',... 75 'not much an expected number(%d)
'],numel(reg),... 78 elseif numel(nRegExpected)==2&&nRegExpected(1)>=0&&... 79 nRegExpected(2)>=nRegExpected(1)&&... 80 all(fix(nRegExpected)==nRegExpected) 82 if ~(nReg<=nRegExpected(2)&&nReg>=nRegExpected(1)) 83 throwerror('wrongParamList
',... 84 ['a number of extracted regular parameters is
',... 85 'expected to be within range %s
'],... 86 mat2str(nRegExpected)); 89 throwerror('wrongInput
',... 90 ['nRegExpected is expected to either a positive integer
',... 91 'scalar or two-element numeric monotinic integer array
']); 94 throwerror('wrongInput
',... 95 'nRegExpected is expected to be of a numeric type
'); 99 if isempty(nPropExpected)&&isnumeric(nPropExpected) 101 elseif numel(nPropExpected)==1&&isnumeric(nPropExpected)&&... 102 nPropExpected>=0&&nPropExpected==fix(nPropExpected) 103 if numel(prop)~=(nPropExpected+nPropExpected) 104 throwerror('wrongParamList
',... 105 ['a number of extracted properties (%d) does not much
',... 106 'an expected number of properties (%d)
'],... 107 numel(prop)*0.5,nPropExpected); 110 throwerror('wrongInput
',... 111 ['nPropExpected is expected to be a numeric non-negative
',... 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 ismembercellstr(in leftList, in rightList, in isHigherIndexUsed)
ISMEMBERCELLSTR produces the same results as the built-in function "ismember" looking for the higher ...
function ismember(in leftVec, in rightVec, in varargin)
ISMEMBER - ismember implementation for arrays of any type.
function parseparams(in args, in propNameList, in nRegExpected, in nPropExpected)
PARSEPARAMS behaves exactly as a built-in Matlab function apart from the incorrect behavior of Matlab...