LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
ParseOptPara.m
1function options=ParseOptPara(options,Names,Types,Values,OptParas)
2
3for i=1:2:size(OptParas,2)
4 prop=OptParas{i};
5 if (i+1 <= size(OptParas,2))
6 value=OptParas{i+1};
7 arg=strmatch(prop,Names,'exact');
8 if (isempty(arg)) % checks whether Invalid Property
9 warning('MATLAB:ParseOptPara:InvalidPropName',...
10 'Property name ''%s'' not recognized and ignored',prop);
11 else
12 if (eval(['is' Types(arg,:) '(value)'])) % checks whether property value is of correct type
13 if (strmatch('char',Types(arg,:),'exact')) % property values are strings
14 %if (isempty(strmatch(value,eval([prop 'Value']),'exact')))
15 if (isempty(strmatch(value,Values{arg},'exact')))
16 warning('MATLAB:ParseOptPara:InvalidPropValue',...
17 'Property value ''%s'' of ''%s'' not allowed and ignored',value,prop);
18 else
19 options.(prop)=value;
20 end
21 elseif (strmatch('numeric',Types(arg,:),'exact')) % property values are numeric
22 options.(prop)=value;
23 end
24 else % incorrect property value type
25 if (ischar(value))
26 warning('MATLAB:ParseOptPara:InvalidPropType',...
27 'Property value ''%s'' of ''%s'' has an incorrect type and is ignored',value,prop);
28
29 end
30 if (isnumeric(value))
31 warning('MATLAB:ParseOptPara:InvalidPropType',...
32 'Property value %d of ''%s'' has an incorrect type and is ignored',value,prop);
33
34 end
35 end
36 end
37 else % odd number of optional parameters
38 warning('MATLAB:ParseOptPara:OddNumbOptParas',...
39 'An odd number of optional parameters detected, last parameter ''%s'' ignored',prop);
40 end
41end