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