comparison m-toolbox/classes/@pest/setYforParameter.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 % SETYFORPARAMETER Sets the according y-value for the specified parameter.
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %
4 % DESCRIPTION: SETYFORPARAMETER Sets the according y-value for the
5 % specified parameter.
6 %
7 % CALL: obj = obj.setYforParameter('a', 1);
8 % obj = obj.setYforParameter('a', 1, 'b', 2);
9 % obj = obj.setYforParameter(plist('values', [1 2],
10 % 'params' {'a', 'b'}))
11 %
12 % INPUTS: obj - one pest model.
13 % pl - parameter list
14 %
15 % <a href="matlab:utils.helper.displayMethodInfo('pest', 'setYforParameter')">Parameters Description</a>
16 %
17 % VERSION: $Id: setYforParameter.m,v 1.7 2011/04/08 08:56:25 hewitson Exp $
18 %
19 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
20
21 function varargout = setYforParameter(varargin)
22
23 % Check if this is a call from a class method
24 callerIsMethod = utils.helper.callerIsMethod;
25
26 if callerIsMethod
27 %%% make sure that the parameters and values are cell-arrays
28 objs = varargin{1};
29 params = cellstr(varargin{2});
30 vals = varargin{3};
31 if ~iscell(vals)
32 vals = num2cell(vals);
33 end
34
35 else
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 %%% Collect input variable names
43 in_names = cell(size(varargin));
44 for ii = 1:nargin,in_names{ii} = inputname(ii);end
45
46 [objs, obj_invars, rest] = utils.helper.collect_objects(varargin(:), '', in_names);
47 [pls, invars, rest] = utils.helper.collect_objects(rest(:), 'plist');
48
49 params = {};
50 vals = {};
51 %%% If pls contains only one plist with the two keys 'params' and
52 %%% 'values' then set the property with a plist.
53 if length(pls) == 1 && isa(pls, 'plist') && nparams(pls) == 2 && isparam(pls, 'values')
54 params = cellstr(find(pls, 'params'));
55 vals = find(pls, 'values');
56 if ~iscell(vals)
57 vals = num2cell(vals);
58 end
59 end
60
61 while numel(rest) >= 2
62 params = [params cellstr(rest{1})];
63 if ~iscell(rest{2})
64 vals = [vals num2cell(rest{2})];
65 else
66 vals = [vals rest{2}];
67 end
68 rest(2) = [];
69 rest(1) = [];
70 end
71
72 %%% Combine plists
73 pls = combine(pls, plist('params', params, 'values', vals));
74
75 if numel(params) ~= numel(vals)
76 error('### Please specify one value per parameter.');
77 end
78
79 end % callerIsMethod
80
81 %%% decide whether we modify the input pest object, or create a new one.
82 objs = copy(objs, nargout);
83
84 for objLoop = 1:numel(objs)
85
86 for ll=1:numel(params)
87 pname = params{ll};
88 % get index of this param
89 idx = find(strcmp(objs(objLoop).names, pname));
90 if isempty(idx)
91 objs(objLoop).names = [objs(objLoop).names {pname}];
92 objs(objLoop).y = [objs(objLoop).y; vals{ll}];
93 else
94 objs(objLoop).y(idx) = vals{ll};
95 end
96 end
97
98 if ~callerIsMethod
99 % set output history
100 objs(objLoop).addHistory(getInfo('None'), pls, obj_invars(objLoop), objs(objLoop).hist);
101 end
102 end
103
104 %%% Set output
105 if nargout == numel(objs)
106 % List of outputs
107 for ii = 1:numel(objs)
108 varargout{ii} = objs(ii);
109 end
110 else
111 % Single output
112 varargout{1} = objs;
113 end
114
115 end
116
117 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
118 % Local Functions %
119 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
120
121 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
122 %
123 % FUNCTION: getInfo
124 %
125 % DESCRIPTION: Get Info Object
126 %
127 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
128
129 function ii = getInfo(varargin)
130 if nargin == 1 && strcmpi(varargin{1}, 'None')
131 sets = {};
132 pl = [];
133 else
134 sets = {'Default'};
135 pl = getDefaultPlist;
136 end
137 % Build info object
138 ii = minfo(mfilename, 'pest', 'ltpda', utils.const.categories.helper, '$Id: setYforParameter.m,v 1.7 2011/04/08 08:56:25 hewitson Exp $', sets, pl);
139 end
140
141 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
142 %
143 % FUNCTION: getDefaultPlist
144 %
145 % DESCRIPTION: Get Default Plist
146 %
147 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
148
149 function plout = getDefaultPlist()
150 persistent pl;
151 if exist('pl', 'var')==0 || isempty(pl)
152 pl = buildplist();
153 end
154 plout = pl;
155 end
156
157 function pl = buildplist()
158
159 pl = plist();
160
161 % Params
162 p = param({'params', 'A cell-array of parameter names.'}, {1, {'{}'}, paramValue.OPTIONAL});
163 pl.append(p);
164
165 % Value
166 p = param({'values', 'A cell-array of values, one for each parameter to set.'}, {1, {'{}'}, paramValue.OPTIONAL});
167 pl.append(p);
168
169 end
170