0001 function args = parseArguments(args, varargin)
0002
0003
0004
0005
0006
0007
0008 if ~isempty(varargin) && isstruct(varargin{1})
0009 arg1 = [fieldnames(varargin{1}), struct2cell(varargin{1})]';
0010 varargin = {arg1{:}, varargin{2 : end}};
0011 end
0012
0013
0014 fields = fieldnames(args);
0015 for i = 1 : 2 : numel(varargin)
0016 target = textscan(varargin{i}, '%s', 'Delimiter', '.');
0017 try
0018 getfield(args, target{1}{:});
0019 catch
0020 if numel(target{1}) == 1 && any(strcmpi(varargin{i}, fields))
0021 target = {fields(find(strcmpi(varargin{i}, fields), 1))};
0022 else
0023 error('Unknown parameter ''%s''', varargin{i});
0024 end
0025 end
0026 args = setfield(args, target{1}{:}, varargin{i + 1});
0027 end