Mercurial > hg > ltpda
comparison m-toolbox/classes/@plist/mfind.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 % MFIND multiple-arguments find routine for a parameter list. | |
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3 % | |
4 % DESCRIPTION: MFIND multiple-arguments find routine for a parameter list. | |
5 % Returns the value corresponding to the first parameter in | |
6 % the list with the search-key list. The search-key list are | |
7 % searched by the order they are entered. | |
8 % If the user specifies two outputs, the second will contain the | |
9 % matching key | |
10 % | |
11 % CALL: a = mfind(pl, 'key1', 'key2', 'key3') | |
12 % [a, key] = mfind(pl, 'key1', 'key2', 'key3') | |
13 % a = mfind(pl, {'key1', 'key2', 'key3'}) | |
14 % [a, key] = mfind(pl, {'key1', 'key2', 'key3'}) | |
15 % a = mfind(pl, plist({'key1', 'key2', 'key3'})) | |
16 % [a, key] = mfind(pl, plist({'key1', 'key2', 'key3'})) | |
17 % | |
18 % EXAMPLES: | |
19 % | |
20 % 1) % get the parameter with key 'foo1', or if not found, get the parameter with key 'foo2' | |
21 % pl = plist('foo2', 5); | |
22 % a = pl.mfind('foo1','foo2') | |
23 % | |
24 % 2) % get the parameter with key 'WIN', or if not found, get the parameter with key 'WIN2' | |
25 % pl = plist('WIN', 'BH92', 'WIN2', 'Hamming'); | |
26 % [a, key] = pl.mfind(plist('key', 'WIN'), 'WIN2') | |
27 % | |
28 % <a href="matlab:utils.helper.displayMethodInfo('plist', 'mfind')">Parameters Description</a> | |
29 % | |
30 % VERSION: $Id: mfind.m,v 1.6 2011/04/08 08:56:21 hewitson Exp $ | |
31 % | |
32 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
33 | |
34 function varargout = mfind(varargin) | |
35 | |
36 %%% Check if this is a call for parameters | |
37 if utils.helper.isinfocall(varargin{:}) | |
38 varargout{1} = getInfo(varargin{3}); | |
39 return | |
40 end | |
41 | |
42 pl = varargin{1}; | |
43 rest = varargin(2:end); | |
44 for jj = 1:numel(rest) | |
45 if isa(rest{jj}, 'plist') | |
46 key = rest{jj}.mfind('key'); | |
47 else | |
48 key = rest{jj}; | |
49 end | |
50 | |
51 if ~isa(key, 'cell') | |
52 key = {key}; | |
53 end | |
54 | |
55 for kk = 1:numel(key) | |
56 %%%%%%%%%% Some plausibility checks %%%%%%%%%% | |
57 if numel(pl) ~= 1 | |
58 error('### This function could only work with one plist-object'); | |
59 end | |
60 | |
61 if ~ischar(key{kk}) | |
62 error('### The ''key'' must be a string but it is from the class %s.', class(key{kk})); | |
63 end | |
64 | |
65 if ~isempty(pl.params) | |
66 dkeys = {pl.params(:).key}; | |
67 else | |
68 dkeys = {''}; | |
69 end | |
70 | |
71 % Get value we want | |
72 matches = strcmpi(key{kk}, dkeys); | |
73 if any(matches) | |
74 val = pl.params(matches).getVal; | |
75 match_key = key{kk}; | |
76 break; | |
77 else | |
78 val = []; | |
79 match_key = []; | |
80 end | |
81 end | |
82 if ~isempty(val) | |
83 break; | |
84 end | |
85 end | |
86 if isa(val, 'ltpda_obj') | |
87 varargout{1} = copy(val, 1); | |
88 else | |
89 varargout{1} = val; | |
90 end | |
91 | |
92 if nargout == 2 | |
93 varargout{2} = match_key; | |
94 end | |
95 end | |
96 | |
97 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
98 % Local Functions % | |
99 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
100 | |
101 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
102 % | |
103 % FUNCTION: getInfo | |
104 % | |
105 % DESCRIPTION: Get Info Object | |
106 % | |
107 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
108 | |
109 function ii = getInfo(varargin) | |
110 if nargin == 1 && strcmpi(varargin{1}, 'None') | |
111 sets = {}; | |
112 pl = []; | |
113 else | |
114 sets = {'Default'}; | |
115 pl = getDefaultPlist; | |
116 end | |
117 % Build info object | |
118 ii = minfo(mfilename, 'plist', 'ltpda', utils.const.categories.helper, '$Id: mfind.m,v 1.6 2011/04/08 08:56:21 hewitson Exp $', sets, pl); | |
119 ii.setModifier(false); | |
120 ii.setArgsmin(1); | |
121 end | |
122 | |
123 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
124 % | |
125 % FUNCTION: getDefaultPlist | |
126 % | |
127 % DESCRIPTION: Get Default Plist | |
128 % | |
129 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
130 | |
131 function pl = getDefaultPlist() | |
132 | |
133 pl = plist(); | |
134 | |
135 % Key | |
136 p = param({'key', 'A key to search for.'}, paramValue.EMPTY_STRING); | |
137 pl.append(p); | |
138 | |
139 end | |
140 |