COMBINE multiple parameter lists (plist objects) into a single plist. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DESCRIPTION: COMBINE multiple parameter lists (plist objects) into a single plist. Duplicate parameters are given priority in the order in which they appear in the input. CALL: pl = combine(p1, p2, p3); pl = combine(p1, [p2 p3], p4) EXAMPLES: >> pl1 = plist(param('A', 1)); >> pl2 = plist(param('A', 3)); >> plo = plist(pl1, pl2) Then plo will contain a parameter 'A' with value 1. VERSION: $Id: combine.html,v 1.14 2008/03/31 10:27:42 hewitson Exp $ HISTORY: 28-04-2007 M Hewitson Creation %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0001 function plo = combine(varargin) 0002 % COMBINE multiple parameter lists (plist objects) into a single plist. 0003 % 0004 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0005 % 0006 % DESCRIPTION: COMBINE multiple parameter lists (plist objects) into a single 0007 % plist. Duplicate parameters are given priority in the order 0008 % in which they appear in the input. 0009 % 0010 % CALL: pl = combine(p1, p2, p3); 0011 % pl = combine(p1, [p2 p3], p4) 0012 % 0013 % EXAMPLES: >> pl1 = plist(param('A', 1)); 0014 % >> pl2 = plist(param('A', 3)); 0015 % >> plo = plist(pl1, pl2) 0016 % 0017 % Then plo will contain a parameter 'A' with value 1. 0018 % 0019 % VERSION: $Id: combine.html,v 1.14 2008/03/31 10:27:42 hewitson Exp $ 0020 % 0021 % HISTORY: 28-04-2007 M Hewitson 0022 % Creation 0023 % 0024 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0025 0026 VERSION = '$Id: combine.html,v 1.14 2008/03/31 10:27:42 hewitson Exp $'; 0027 CATEGORY = 'Helper'; 0028 0029 % Check if this is a call for parameters 0030 if nargin == 2 0031 if isa(varargin{1}, 'plist') && ischar(varargin{2}) 0032 in = char(varargin{2}); 0033 if strcmp(in, 'Params') 0034 plo = plist; 0035 return 0036 elseif strcmp(in, 'Version') 0037 plo = VERSION; 0038 return 0039 elseif strcmp(in, 'Category') 0040 plo = CATEGORY; 0041 return 0042 end 0043 end 0044 end 0045 0046 % get input plists 0047 % this code allows for inputs of the form: 0048 % >> pl = combine([p1 p2], p, [p3 p4], p5, p6) 0049 % or some combination of that. 0050 pls = []; 0051 for j=1:length(varargin) 0052 pj = varargin{j}; 0053 if isa(pj, 'plist') 0054 pj = reshape(pj, 1, []); 0055 pls = [pls pj]; 0056 end 0057 end 0058 0059 % The properties of the output plist is corresponding to the input plist 0060 plo = pls(1); 0061 0062 % Loop over all plist's 0063 for ii = 2:length(pls) 0064 0065 % Loop over all params in the current plist 0066 for jj = 1:length(pls(ii).params) 0067 0068 ps = pls(ii).params(jj); 0069 plo = add_param(plo, ps); 0070 0071 end 0072 0073 end 0074 0075 0076 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0077 % 0078 % DESCRIPTION: The input parameter will only be added if the key doesn't exist 0079 % in the plist. 0080 % 0081 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0082 function pl = add_param(pl, param) 0083 0084 for ii = 1:nparams(pl) 0085 if strcmpi(pl.params(ii).key, param.key) 0086 % If the key exist in pl then do nothing, otherwise add the key value pair. 0087 return 0088 end 0089 end 0090 0091 % Convert all key characters into upper case characters 0092 param.key = upper(param.key); 0093 0094 pl.params = [pl.params param]; 0095 0096 0097 % END 0098