Mercurial > hg > ltpda
comparison m-toolbox/classes/@ssm/setParameters.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 % SETPARAMETERS Sets the values of the given parameters. | |
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3 % | |
4 % DESCRIPTION: SETPARAMETERS Sets the values of the given parameters. | |
5 % | |
6 % CALL: obj = obj.setParameters(plist); | |
7 % | |
8 % <a href="matlab:utils.helper.displayMethodInfo('ssm', 'setParameters')">Parameters Description</a> | |
9 % | |
10 % VERSION: $Id: setParameters.m,v 1.17 2011/04/08 08:56:23 hewitson Exp $ | |
11 % | |
12 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
13 | |
14 function varargout = setParameters(varargin) | |
15 | |
16 % Check if this is a call for parameters | |
17 if utils.helper.isinfocall(varargin{:}) | |
18 varargout{1} = getInfo(varargin{3}); | |
19 return | |
20 end | |
21 | |
22 %% starting initial checks | |
23 utils.helper.msg(utils.const.msg.MNAME, ['running ', mfilename]); | |
24 | |
25 % handle 'internal' call | |
26 if ischar(varargin{end}) && strcmpi(varargin{end}, 'internal') | |
27 isInternal = true; | |
28 else | |
29 isInternal = false; | |
30 end | |
31 | |
32 | |
33 % Collect input variable names | |
34 in_names = cell(size(varargin)); | |
35 for ii = 1:nargin, in_names{ii} = inputname(ii); end | |
36 | |
37 % Collect all SSMs and options | |
38 [sys, ssm_invars, rest] = utils.helper.collect_objects(varargin(:), 'ssm', in_names); | |
39 pl = utils.helper.collect_objects(rest(:), 'plist'); | |
40 | |
41 if ~isInternal | |
42 pl = combine(pl, getDefaultPlist()); | |
43 end | |
44 | |
45 %% processing input | |
46 setnames = pl.find('names'); | |
47 if ischar(setnames) | |
48 setnames = {setnames}; | |
49 elseif ~iscellstr(setnames) | |
50 error('### Parameter names must be a cell-array of strings') | |
51 end | |
52 | |
53 setvalues = pl.find('values'); | |
54 if ~isa(setvalues, 'double') | |
55 error('### param values should be a double') | |
56 end | |
57 | |
58 Nsys = numel(sys); | |
59 sys_out = copy(sys,nargout); | |
60 | |
61 %% checking data | |
62 Nset = length(setnames); | |
63 if ~(Nset== length(setvalues)) | |
64 error(['### The number of parameter names is ' num2str(Nset) ' and the number of parameter values is ' num2str(length(setvalues))]); | |
65 end | |
66 if ~isa(setvalues, 'double') | |
67 error(['### Parameter ''values'' is not a double array but of class ' class(setvalues)]); | |
68 end | |
69 | |
70 %% proceeding parameters update | |
71 for i_sys = 1:Nsys | |
72 sys_out(i_sys).doSetParameters(setnames, setvalues); | |
73 if ~isInternal | |
74 sys_out(i_sys).addHistory(getInfo('None'), plist('names',setnames, 'values', setvalues ), ssm_invars(i_sys), sys_out(i_sys).hist ); | |
75 end | |
76 end | |
77 | |
78 if nargout == numel(sys_out) | |
79 for ii = 1:numel(sys_out) | |
80 varargout{ii} = sys_out(ii); | |
81 end | |
82 else | |
83 varargout{1} = sys_out; | |
84 end | |
85 | |
86 end | |
87 | |
88 | |
89 | |
90 %-------------------------------------------------------------------------- | |
91 % Get Info Object | |
92 %-------------------------------------------------------------------------- | |
93 function ii = getInfo(varargin) | |
94 | |
95 if nargin == 1 && strcmpi(varargin{1}, 'None') | |
96 sets = {}; | |
97 pl = []; | |
98 else | |
99 sets = {'Default'}; | |
100 pl = getDefaultPlist; | |
101 end | |
102 % Build info object | |
103 ii = minfo(mfilename, 'ssm', 'ltpda', utils.const.categories.helper, '$Id: setParameters.m,v 1.17 2011/04/08 08:56:23 hewitson Exp $', sets, pl); | |
104 end | |
105 | |
106 %-------------------------------------------------------------------------- | |
107 % Get Default Plist | |
108 %-------------------------------------------------------------------------- | |
109 function pl = getDefaultPlist() | |
110 pl = plist(); | |
111 | |
112 p = param({'names', 'A cell-array of parameter names for numerical substitutions.'}, {}); | |
113 pl.append(p); | |
114 | |
115 p = param({'values', 'An array of parameter values for numerical substitutions.'}, []); | |
116 pl.append(p); | |
117 end |