comparison m-toolbox/classes/@ssm/keepParameters.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 % KEEPPARAMETERS enables to substitute symbollic patameters
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %
4 % DESCRIPTION: KEEPPARAMETERS enables the substitution of symbolic parameters.
5 % The parameters substituted are then removed from the params field.
6 % The function can be applied on an array of objects.
7 %
8 % CALL: varargout = keepParameters(varargin)
9 % obj = obj.keepParameters(plist)
10 % obj = obj.keepParameter % substitutes all parameters
11 % % i.e., keep none.
12 %
13 % <a href="matlab:utils.helper.displayMethodInfo('ssm', 'keepParameters')">Parameters Description</a>
14 %
15 % VERSION: $Id: keepParameters.m,v 1.16 2011/04/08 08:56:22 hewitson Exp $
16 %
17 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
18
19 function varargout = keepParameters(varargin)
20
21 callerIsMethod = utils.helper.callerIsMethod;
22
23 %% starting initial checks
24 % Check if this is a call for parameters
25 if utils.helper.isinfocall(varargin{:})
26 varargout{1} = getInfo(varargin{3});
27 return
28 end
29
30 utils.helper.msg(utils.const.msg.MNAME, ['running ', mfilename]);
31
32 % Collect input variable names
33 in_names = cell(size(varargin));
34 for ii = 1:nargin, in_names{ii} = inputname(ii); end
35
36 % Collect all SSMs and options
37 [sys, ssm_invars, rest] = utils.helper.collect_objects(varargin(:), 'ssm', in_names);
38 [pl, pl_invars, rest] = utils.helper.collect_objects(rest(:), 'plist');
39 if ~isempty(rest)
40 pl = combine(pl, plist(rest{:}));
41 end
42 pl = combine(pl, getDefaultPlist());
43
44 %% processing input
45 keepnames = pl.find('names');
46 if ischar(keepnames)
47 keepnames = {keepnames};
48 elseif ~iscellstr(keepnames)
49 error('param names be a cellstr')
50 end
51
52 %% Decide on a deep copy or a modify, depending on the output
53 sys_out = copy(sys, nargout);
54 Nsys = numel(sys);
55
56 for i_sys = 1:Nsys
57 % generating 'subsnames' out of 'keepnames'
58 paramnames = sys_out(i_sys).paramnames;
59 subsnames = cell(1,0);
60 for j=1:numel(paramnames)
61 comparison = strcmp(paramnames{j}, keepnames);
62 if sum(comparison)==0
63 subsnames = [subsnames paramnames{j}]; %#ok<AGROW>
64 end
65 end
66
67 sys_out(i_sys).doSubsParameters(subsnames, callerIsMethod);
68 sys_out(i_sys).addHistory(getInfo('None'), pl, {''}, sys_out(i_sys).hist );
69 end
70
71 if nargout == numel(sys_out)
72 for ii = 1:numel(sys_out)
73 varargout{ii} = sys_out(ii);
74 end
75 else
76 varargout{1} = sys_out;
77 end
78 end
79
80 %--------------------------------------------------------------------------
81 % Get Info Object
82 %--------------------------------------------------------------------------
83 function ii = getInfo(varargin)
84
85 if nargin == 1 && strcmpi(varargin{1}, 'None')
86 sets = {};
87 pl = [];
88 else
89 sets = {'Default'};
90 pl = getDefaultPlist;
91 end
92 % Build info object
93 ii = minfo(mfilename, 'ssm', 'ltpda', utils.const.categories.op, '$Id: keepParameters.m,v 1.16 2011/04/08 08:56:22 hewitson Exp $', sets, pl);
94 end
95
96 %--------------------------------------------------------------------------
97 % Get Default Plist
98 %--------------------------------------------------------------------------
99 function pl = getDefaultPlist()
100 pl = plist();
101
102 p = param({'names', 'A cell-array of parameter names to be kept symbolic.'}, {} );
103 pl.append(p);
104
105 end
106
107