Mercurial > hg > ltpda
comparison m-toolbox/classes/@smodel/assignalias.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 % ASSIGNALIAS assign values to smodel alias | |
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3 % | |
4 % DESCRIPTION: ASSIGNALIAS assign numerical values or vectors to smodel | |
5 % aliases. This is a processing method which should be run before using the | |
6 % given smodel inside smodel/fftfilt so to gain evaluation time during the | |
7 % evaluation of the model. Be careful to insert the correct values for the | |
8 % parameters otherwhise smodel/double will throw an error. | |
9 % | |
10 % CALL: mdl = assignalias(mdl) | |
11 % | |
12 % <a href="matlab:utils.helper.displayMethodInfo('smodel', 'assignalias')">Parameters Description</a> | |
13 % | |
14 % VERSION: $Id: assignalias.m,v 1.6 2011/05/10 11:07:59 luigi Exp $ | |
15 % | |
16 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
17 | |
18 function varargout = assignalias(varargin) | |
19 | |
20 % Check if this is a call for parameters | |
21 if utils.helper.isinfocall(varargin{:}) | |
22 varargout{1} = getInfo(varargin{3}); | |
23 return | |
24 end | |
25 | |
26 % Collect input variable names | |
27 in_names = cell(size(varargin)); | |
28 for ii = 1:nargin | |
29 in_names{ii} = inputname(ii); | |
30 end | |
31 | |
32 % Collect all smodels and plists | |
33 [as, smodel_invars, rest] = utils.helper.collect_objects(varargin(:), 'smodel', in_names); | |
34 pl = utils.helper.collect_objects(varargin(:), 'plist'); | |
35 | |
36 | |
37 % Copy the object(s), so to inherit parameters etc | |
38 mdls = copy(as, nargout); | |
39 | |
40 % combine plists | |
41 if isempty(pl) | |
42 setvar = 'fftfilt'; | |
43 else | |
44 xvals = find(pl, 'xvals'); | |
45 if isempty(xvals) | |
46 setvar = 'fftfilt'; | |
47 else | |
48 setvar = 'UserDefinedXvals'; | |
49 end | |
50 end | |
51 | |
52 pl = parse(pl, getDefaultPlist(setvar)); | |
53 | |
54 % get parameters values from plist | |
55 switch lower(setvar) | |
56 case 'fftfilt' | |
57 nsecs = find(pl, 'nsecs'); | |
58 npad = find(pl, 'npad'); | |
59 fs = find(pl, 'fs'); | |
60 % get fft frequancies | |
61 nfft = nsecs*fs + npad; | |
62 xvals = utils.math.getfftfreq(nfft,fs,'one'); | |
63 xvals = xvals.'; | |
64 case 'userdefinedxvals' | |
65 xvals = find(pl, 'xvals'); | |
66 end | |
67 | |
68 % run over input objects | |
69 for ii=1:numel(mdls) | |
70 % Recover the mapping factor from xvals and xvar | |
71 % get xvar | |
72 xxvar = mdls(ii).xvar; | |
73 % check dimensions | |
74 if numel(xxvar)>1 | |
75 error('Multiple xvar are not supported!') | |
76 else | |
77 xxvar = xxvar{:}; | |
78 end | |
79 trans = mdls(ii).trans; | |
80 if isempty(trans) | |
81 scale = 1.0; | |
82 else | |
83 if isnumeric(trans) | |
84 scale = trans; | |
85 elseif ischar(trans) | |
86 scale = eval(trans); | |
87 elseif iscell(trans) | |
88 % check dimension | |
89 if numel(trans)>1 | |
90 error('Multiple trans are not supported!') | |
91 else | |
92 switch lower(class(trans{:})) | |
93 case 'double' | |
94 scale = trans{:}; | |
95 case 'char' | |
96 scale = eval(trans{:}); | |
97 end | |
98 end | |
99 else | |
100 error('Unknown format for the transformation!'); | |
101 end | |
102 end | |
103 % assign values for the x | |
104 getSingleVariable(xxvar,scale.*xvals); | |
105 % assign alias values | |
106 for jj=1:numel(mdls(ii).aliasNames) | |
107 switch class(mdls(ii).aliasValues{jj}) | |
108 case 'char' | |
109 getSingleVariable('calias',eval(mdls(ii).aliasValues{jj})); | |
110 mdls(ii).aliasValues{jj} = calias; | |
111 case 'smodel' | |
112 tmd = mdls(ii).aliasValues{jj}; | |
113 tmd.setXvals(xvals); | |
114 getSingleVariable('calias',tmd.double); | |
115 mdls(ii).aliasValues{jj} = calias; | |
116 otherwise | |
117 % do nothing | |
118 end | |
119 end | |
120 mdls(ii).setXvals(xvals); | |
121 % set output history | |
122 mdls(ii).addHistory(getInfo('None'), pl, smodel_invars(ii), mdls(ii).hist); | |
123 end | |
124 | |
125 %%% Set output | |
126 if nargout == numel(mdls) | |
127 % List of outputs | |
128 for ii = 1:numel(mdls) | |
129 varargout{ii} = mdls(ii); | |
130 end | |
131 else | |
132 % Single output | |
133 varargout{1} = mdls; | |
134 end | |
135 | |
136 end | |
137 | |
138 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
139 % Local Functions % | |
140 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
141 | |
142 | |
143 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
144 % | |
145 % FUNCTION: getCellVariables | |
146 % | |
147 % DESCRIPTION: Assign values to variables | |
148 % | |
149 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
150 function getSingleVariable(nms,val) | |
151 assignin('caller',nms,val); | |
152 end | |
153 | |
154 %-------------------------------------------------------------------------- | |
155 % Get Info Object | |
156 %-------------------------------------------------------------------------- | |
157 function ii = getInfo(varargin) | |
158 if nargin == 1 && strcmpi(varargin{1}, 'None') | |
159 sets = {}; | |
160 pl = []; | |
161 elseif nargin == 1 && ~isempty(varargin{1}) && ischar(varargin{1}) | |
162 sets{1} = varargin{1}; | |
163 pl = getDefaultPlist(sets{1}); | |
164 else | |
165 sets = SETS(); | |
166 % get plists | |
167 pl(size(sets)) = plist; | |
168 for kk = 1:numel(sets) | |
169 pl(kk) = getDefaultPlist(sets{kk}); | |
170 end | |
171 end | |
172 % Build info object | |
173 ii = minfo(mfilename, 'smodel', 'ltpda', utils.const.categories.helper, '$Id: assignalias.m,v 1.6 2011/05/10 11:07:59 luigi Exp $', sets, pl); | |
174 end | |
175 | |
176 | |
177 %-------------------------------------------------------------------------- | |
178 % Defintion of Sets | |
179 %-------------------------------------------------------------------------- | |
180 | |
181 function out = SETS() | |
182 out = {... | |
183 'fftfilt', ... | |
184 'UserDefinedXvals' ... | |
185 }; | |
186 end | |
187 | |
188 | |
189 %-------------------------------------------------------------------------- | |
190 % Get Default Plist | |
191 %-------------------------------------------------------------------------- | |
192 function plout = getDefaultPlist(set) | |
193 persistent pl; | |
194 persistent lastset; | |
195 if exist('pl', 'var')==0 || isempty(pl) || ~strcmp(lastset, set) | |
196 pl = buildplist(set); | |
197 lastset = set; | |
198 end | |
199 plout = pl; | |
200 end | |
201 | |
202 function pl = buildplist(set) | |
203 pl = plist.EMPTY_PLIST; | |
204 | |
205 switch lower(set) | |
206 case 'fftfilt' | |
207 p = param({'nsecs', 'Number of seconds of the time series will be filtered with fftfilt.'}, paramValue.DOUBLE_VALUE(1)); | |
208 pl.append(p); | |
209 | |
210 p = param({'npad', 'Number of sample pad will will be used in fftfilt.'}, paramValue.EMPTY_DOUBLE); | |
211 pl.append(p); | |
212 | |
213 p = param({'fs', 'Sampling frequency of the time series will be filtered with fftfilt.'}, paramValue.DOUBLE_VALUE(1)); | |
214 pl.append(p); | |
215 | |
216 | |
217 | |
218 case 'userdefinedxvals' | |
219 | |
220 p = param({'xvals', 'A vector of values for the X variable.'... | |
221 'If the smodel implement a transformation for x values then you should'... | |
222 'input the value before the transformation. E.g. xvar = s -> trans = 2*pi*i'... | |
223 'you should input f values so you finally get inside the code xvals = 2*pi*i*f'}, paramValue.EMPTY_DOUBLE); | |
224 pl.append(p); | |
225 | |
226 | |
227 end | |
228 end |