Mercurial > hg > ltpda
comparison m-toolbox/classes/@smodel/eval.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 % EVAL evaluates the symbolic model and returns an AO containing the numeric data. | |
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3 % | |
4 % DESCRIPTION: EVAL evaluates the symbolic model and returns an AO | |
5 % containing the numeric data. | |
6 % | |
7 % CALL: mdl = eval(mdl) | |
8 % | |
9 % <a href="matlab:utils.helper.displayMethodInfo('smodel', 'eval')">Parameters Description</a> | |
10 % | |
11 % VERSION: $Id: eval.m,v 1.28 2011/07/11 05:17:37 mauro Exp $ | |
12 % | |
13 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
14 | |
15 function varargout = eval(varargin) | |
16 | |
17 % Check if this is a call for parameters | |
18 if utils.helper.isinfocall(varargin{:}) | |
19 varargout{1} = getInfo(varargin{3}); | |
20 return | |
21 end | |
22 | |
23 % Collect input variable names | |
24 in_names = cell(size(varargin)); | |
25 for ii = 1:nargin,in_names{ii} = inputname(ii);end | |
26 | |
27 % Collect all SMODELs | |
28 [mdl, mdl_invars] = utils.helper.collect_objects(varargin(:), 'smodel', in_names); | |
29 | |
30 if numel(mdl) ~= 1 | |
31 error('### eval can only evaluate one model at a time.'); | |
32 end | |
33 | |
34 % Apply defaults to plist | |
35 pl = applyDefaults(getDefaultPlist(), varargin{:}); | |
36 | |
37 % Put together the plist to build the AO | |
38 pl_ao = plist(); | |
39 | |
40 % get the output Y values | |
41 yout = mdl.double(); | |
42 | |
43 % get the output X values | |
44 xout = find(pl, 'output x'); | |
45 | |
46 % Check the X axis properties (values, type, units) | |
47 switch class(xout) | |
48 case 'ao' | |
49 % In this case, we just copy the object and change the values of the y field | |
50 bs = copy(xout, true); | |
51 % Set y values | |
52 bs.setY(yout); | |
53 % Clear the errors | |
54 bs.setDy([]); | |
55 % Set y units | |
56 bs.setYunits(mdl.yunits); | |
57 | |
58 case 'double' | |
59 if ~isempty(xout) | |
60 % set the X values | |
61 if numel(xout) ~= numel(yout) | |
62 error('LTPDA:err:SizeMismatch', 'The ''y'' field of the destination object has different size than the input ''x'' values'); | |
63 end | |
64 pl_ao.pset('xvals', xout); | |
65 | |
66 % set the output X units | |
67 pl_ao.pset('xunits', find(pl, 'output xunits')); | |
68 | |
69 % output object data type | |
70 data_type = find(pl, 'output type'); | |
71 if isempty(data_type) | |
72 data_type = 'cdata'; | |
73 end | |
74 pl_ao.pset('type', data_type); | |
75 | |
76 switch data_type | |
77 case 'tsdata' | |
78 % set T0 | |
79 pl_ao.pset('t0', find(pl, 't0')); | |
80 case {'fsdata', 'xydata'} | |
81 % nothing to do | |
82 case 'cdata' | |
83 % inconsistency | |
84 error('LTPDA:err:InfoMismatch', 'You set the [output x] property, but also specified class ''%s'' for the [output data] property', data_type); | |
85 otherwise | |
86 error('LTPDA:err:UnsupportedClass', 'Unsupported class ''%s'' for the [output data] property', data_type); | |
87 end | |
88 % set the Y values | |
89 pl_ao.pset('yvals', yout); | |
90 | |
91 else | |
92 % No more info available on the object. Go for a cdata AO | |
93 % set the Y values | |
94 pl_ao.pset('vals', yout); | |
95 end | |
96 | |
97 % Set Y units | |
98 pl_ao.pset('yunits', mdl.yunits); | |
99 | |
100 % Build the AO | |
101 bs = ao(pl_ao); | |
102 otherwise | |
103 error('LTPDA:err:UnsupportedClass', 'Unsupported class ''%s'' for the [output x] property', class(xout)); | |
104 end | |
105 | |
106 | |
107 % Set name | |
108 bs.setName(sprintf('eval(%s)', mdl.name)); | |
109 % Add history | |
110 bs.addHistory(getInfo('None'), pl, mdl_invars, mdl.hist); | |
111 | |
112 % Set output | |
113 varargout{1} = bs; | |
114 end | |
115 | |
116 %-------------------------------------------------------------------------- | |
117 % Get Info Object | |
118 %-------------------------------------------------------------------------- | |
119 function ii = getInfo(varargin) | |
120 if nargin == 1 && strcmpi(varargin{1}, 'None') | |
121 sets = {}; | |
122 pl = []; | |
123 else | |
124 sets = {'Default'}; | |
125 pl = getDefaultPlist(); | |
126 end | |
127 % Build info object | |
128 ii = minfo(mfilename, 'smodel', 'ltpda', utils.const.categories.helper, '$Id: eval.m,v 1.28 2011/07/11 05:17:37 mauro Exp $', sets, pl); | |
129 ii.setModifier(false); | |
130 end | |
131 | |
132 %-------------------------------------------------------------------------- | |
133 % Get Default Plist | |
134 %-------------------------------------------------------------------------- | |
135 | |
136 function plout = getDefaultPlist() | |
137 persistent pl; | |
138 if ~exist('pl', 'var') || isempty(pl) | |
139 pl = buildplist(); | |
140 end | |
141 plout = pl; | |
142 end | |
143 | |
144 function pl = buildplist() | |
145 pl = plist(); | |
146 | |
147 % output type | |
148 pv = paramValue.DATA_TYPES; | |
149 % Add an 'empty' at the end of the list | |
150 pv{2} = [pv{2} {''}]; | |
151 p = param({'output type',['Choose the output data type.<br>']}, pv); | |
152 p.val.setValIndex(1); | |
153 pl.append(p); | |
154 | |
155 % output x | |
156 p = param({'output x', ['The X values for the output data ao. This can be:<ul>'... | |
157 '<li>a double vector </li>' ... | |
158 '<li>an ao, in this case the output is a copy of this object BUT the ''y'' field is calculated from the model</li></ul>' ... | |
159 ]}, paramValue.EMPTY_DOUBLE); | |
160 pl.append(p); | |
161 | |
162 % output Xunits | |
163 p = param({'output xunits','The X units for the output data ao'}, paramValue.STRING_VALUE('')); | |
164 pl.append(p); | |
165 | |
166 % T0 | |
167 p = param({'T0', ['The UTC time of the first sample. <br>' ... | |
168 'Note this applies only to the case where you specify ''output type'' to be ''tsdata''']}, {1, {'1970-01-01 00:00:00.000'}, paramValue.OPTIONAL}); | |
169 pl.append(p); | |
170 | |
171 end | |
172 |