Mercurial > hg > ltpda
comparison m-toolbox/classes/@ssm/findParameters.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 % findParameters returns parameter names matching the given pattern. | |
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3 % | |
4 % DESCRIPTION: findParameters returns parameter names matching the given | |
5 % pattern. | |
6 % | |
7 % CALL: | |
8 % names = findParameters(sys, options) | |
9 % | |
10 % INPUTS: | |
11 % sys - ssm objects | |
12 % options - plist of options | |
13 % | |
14 % OUTPUTS: | |
15 % names - a cell-array of matches, one cell per input pattern. | |
16 % Each cell can contain a cell-array of matched parameter | |
17 % names. | |
18 % | |
19 % <a href="matlab:utils.helper.displayMethodInfo('ssm', 'findParameters')">Parameters Description</a> | |
20 % | |
21 % VERSION: $Id: findParameters.m,v 1.10 2011/04/08 08:56:22 hewitson Exp $ | |
22 % | |
23 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
24 | |
25 function varargout = findParameters(varargin) | |
26 | |
27 %% starting initial checks | |
28 % Check if this is a call for parameters | |
29 if utils.helper.isinfocall(varargin{:}) | |
30 varargout{1} = getInfo(varargin{3}); | |
31 return | |
32 end | |
33 | |
34 utils.helper.msg(utils.const.msg.MNAME, ['running ', mfilename]); | |
35 | |
36 % Collect input variable names | |
37 in_names = cell(size(varargin)); | |
38 for ii = 1:nargin, in_names{ii} = inputname(ii); end | |
39 | |
40 % Collect all SSMs and options | |
41 [sys, ssm_invars, rest] = utils.helper.collect_objects(varargin(:), 'ssm', in_names); | |
42 [pl, invars2, rest] = utils.helper.collect_objects(rest(:), 'plist'); | |
43 if ~isempty(rest) | |
44 pl = combine(pl, plist(rest{:})); | |
45 end | |
46 pl = combine(pl, getDefaultPlist()); | |
47 | |
48 % ... and from the plist | |
49 patterns = find(pl, 'patterns'); | |
50 fieldName = find(pl, 'field'); | |
51 if ~iscell(patterns), patterns = {patterns}; end | |
52 | |
53 utils.helper.msg(utils.const.msg.PROC1, 'matching against:'); | |
54 for jj=1:numel(patterns) | |
55 utils.helper.msg(utils.const.msg.PROC1, ' %s', patterns{jj}); | |
56 end | |
57 | |
58 % Loop over input systems | |
59 parameters = plist.initObjectWithSize(numel(sys),1); | |
60 for jj=1:numel(sys) | |
61 % loop over patterns | |
62 snames = {}; | |
63 switch lower(fieldName) | |
64 case 'params' | |
65 plparams = sys(jj).params; | |
66 case 'numparams' | |
67 plparams = sys(jj).numparams; | |
68 otherwise | |
69 error('The only possibilities for the option "field" are "params" and "numparams".') | |
70 end | |
71 | |
72 for kk=1:numel(patterns) | |
73 for ll=1:plparams.nparams | |
74 res = regexp(plparams.params(ll).key, patterns{kk}, 'match'); | |
75 if ~isempty(res) | |
76 snames = [snames plparams.params(ll).key]; %#ok<AGROW> | |
77 end | |
78 end | |
79 end | |
80 if ~isempty(snames) | |
81 parameters(jj) = copy( plparams.subset(snames), 1); | |
82 end | |
83 end | |
84 | |
85 % Set outputs | |
86 if nargout == numel(parameters) | |
87 for ii=1:numel(parameters) | |
88 varargout{ii} = parameters(ii); | |
89 end | |
90 else | |
91 varargout{1} = parameters; | |
92 end | |
93 end | |
94 | |
95 | |
96 %-------------------------------------------------------------------------- | |
97 % Get Info Object | |
98 %-------------------------------------------------------------------------- | |
99 function ii = getInfo(varargin) | |
100 | |
101 if nargin == 1 && strcmpi(varargin{1}, 'None') | |
102 sets = {}; | |
103 pl = []; | |
104 else | |
105 sets = {'Default'}; | |
106 pl = getDefaultPlist; | |
107 end | |
108 % Build info object | |
109 ii = minfo(mfilename, 'ssm', 'ltpda', utils.const.categories.output, '$Id: findParameters.m,v 1.10 2011/04/08 08:56:22 hewitson Exp $', sets, pl); | |
110 end | |
111 | |
112 %-------------------------------------------------------------------------- | |
113 % Get Default Plist | |
114 %-------------------------------------------------------------------------- | |
115 function pl = getDefaultPlist() | |
116 pl = plist(); | |
117 | |
118 % keys | |
119 p = param({'patterns', 'patterns to search for in the plist.'}, paramValue.EMPTY_CELL ); | |
120 pl.append(p); | |
121 % plist | |
122 p = param({'field','Choose to look for in the field params or numparams.'},... | |
123 {1, {'params', 'numparams'}, paramValue.SINGLE}); | |
124 pl.append(p); | |
125 | |
126 end | |
127 |