Mercurial > hg > ltpda
comparison m-toolbox/classes/@plist/remove.m @ 0:f0afece42f48
Import.
author | Daniele Nicolodi <nicolodi@science.unitn.it> |
---|---|
date | Wed, 23 Nov 2011 19:22:13 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:f0afece42f48 |
---|---|
1 % REMOVE remove a parameter from the parameter list. | |
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3 % | |
4 % DESCRIPTION: REMOVE remove a parameter from the parameter list. | |
5 % | |
6 % CALL: pl = remove(pl, 2) - removes 2nd in the list | |
7 % pl = remove(pl, 'key') - removes parameter called 'key' | |
8 % pl = remove(pl, 'key1', 'key2') | |
9 % pl = remove(pl, [1 2]) | |
10 % | |
11 % <a href="matlab:utils.helper.displayMethodInfo('plist', 'remove')">Parameters Description</a> | |
12 % | |
13 % VERSION: $Id: remove.m,v 1.26 2011/04/08 08:56:21 hewitson Exp $ | |
14 % | |
15 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
16 | |
17 function varargout = remove(varargin) | |
18 | |
19 %%% Check if this is a call for parameters | |
20 if utils.helper.isinfocall(varargin{:}) | |
21 varargout{1} = getInfo(varargin{3}); | |
22 return | |
23 end | |
24 | |
25 [objs, invars, rest] = utils.helper.collect_objects(varargin(:), 'plist'); | |
26 | |
27 % Decide on a deep copy or a modify | |
28 objs = copy(objs, nargout); | |
29 | |
30 keys = rest; | |
31 | |
32 for ii = 1:numel(objs) | |
33 pl = objs(ii); | |
34 | |
35 for jj = 1:numel(keys) | |
36 | |
37 if ischar(keys{jj}) | |
38 %%%%% Remove specified key %%%%% | |
39 idx = []; | |
40 np = length(pl.params); | |
41 for i=1:np | |
42 key = pl.params(i).key; | |
43 if ~strcmpi(key, keys{jj}) | |
44 idx = [idx i]; | |
45 end | |
46 end | |
47 pl.params = pl.params(idx); | |
48 if length(idx) == np | |
49 warning('!!! No parameter found matching key name in %dth plist', ii); | |
50 end | |
51 | |
52 elseif isnumeric(keys{jj}) | |
53 %%%%% Remove specified position %%%%% | |
54 | |
55 if max(keys{jj}) > numel(pl.params) | |
56 error('### Index exceeds number of parameters in %dth plist', ii); | |
57 end | |
58 pl.params(keys{jj}) = []; | |
59 | |
60 elseif islogical(keys{jj}) | |
61 %%%%% Remove specified logical position %%%%% | |
62 | |
63 if numel(keys{jj}) ~= numel(pl.params) | |
64 error('### The logical index doesn''t have the same size as the number of parameters.'); | |
65 end | |
66 pl.params(keys{jj}) = []; | |
67 | |
68 else | |
69 %%%%% Unknown method %%%%% | |
70 error('### unknown indexing method') | |
71 end | |
72 | |
73 end % Loop over the 'keys' | |
74 | |
75 if isempty(pl.params) | |
76 pl.params = []; | |
77 end | |
78 objs(ii) = pl; | |
79 end % Loop over the objects. | |
80 | |
81 varargout{1} = objs; | |
82 end | |
83 | |
84 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
85 % Local Functions % | |
86 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
87 | |
88 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
89 % | |
90 % FUNCTION: getInfo | |
91 % | |
92 % DESCRIPTION: Get Info Object | |
93 % | |
94 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
95 | |
96 function ii = getInfo(varargin) | |
97 if nargin == 1 && strcmpi(varargin{1}, 'None') | |
98 sets = {}; | |
99 pl = []; | |
100 else | |
101 sets = {'Default'}; | |
102 pl = getDefaultPlist; | |
103 end | |
104 % Build info object | |
105 ii = minfo(mfilename, 'plist', 'ltpda', utils.const.categories.helper, '$Id: remove.m,v 1.26 2011/04/08 08:56:21 hewitson Exp $', sets, pl); | |
106 ii.setArgsmin(1); | |
107 end | |
108 | |
109 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
110 % | |
111 % FUNCTION: getDefaultPlist | |
112 % | |
113 % DESCRIPTION: Get Default Plist | |
114 % | |
115 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
116 | |
117 | |
118 function pl = getDefaultPlist() | |
119 | |
120 pl = plist(); | |
121 | |
122 % Key | |
123 p = param({'key', 'The key of the parameter to remove.'}, paramValue.EMPTY_STRING); | |
124 pl.append(p); | |
125 | |
126 end | |
127 |