Mercurial > hg > ltpda
comparison m-toolbox/classes/@ao/integrate.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 % INTEGRATE integrates the data in AO. | |
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3 % | |
4 % DESCRIPTION: INTEGRATE integrates the data in AO. The result is a single | |
5 % valued AO. | |
6 % | |
7 % CALL: bs = integrate(a1,a2,a3,...,pl) | |
8 % bs = integrate(as,pl) | |
9 % bs = as.integrate(pl) | |
10 % | |
11 % INPUTS: aN - input analysis objects | |
12 % as - input analysis objects array | |
13 % pl - input parameter list | |
14 % | |
15 % OUTPUTS: bs - array of analysis objects, one for each input, | |
16 % containing the integrate data | |
17 % | |
18 % <a href="matlab:utils.helper.displayMethodInfo('ao', 'integrate')">Parameters Description</a> | |
19 % | |
20 % VERSION: $Id: integrate.m,v 1.11 2011/04/08 08:56:11 hewitson Exp $ | |
21 % | |
22 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
23 | |
24 function varargout = integrate(varargin) | |
25 | |
26 % Check if this is a call for parameters | |
27 if utils.helper.isinfocall(varargin{:}) | |
28 varargout{1} = getInfo(varargin{3}); | |
29 return | |
30 end | |
31 | |
32 import utils.const.* | |
33 utils.helper.msg(msg.PROC3, 'running %s/%s', mfilename('class'), mfilename); | |
34 | |
35 % Collect input variable names | |
36 in_names = cell(size(varargin)); | |
37 for ii = 1:nargin,in_names{ii} = inputname(ii);end | |
38 | |
39 % Collect all AOs and plists | |
40 [as, ao_invars] = utils.helper.collect_objects(varargin(:), 'ao', in_names); | |
41 pl = utils.helper.collect_objects(varargin(:), 'plist', in_names); | |
42 | |
43 % Decide on a deep copy or a modify | |
44 bs = copy(as, nargout); | |
45 | |
46 % combine plists | |
47 pl = parse(pl, getDefaultPlist()); | |
48 | |
49 | |
50 % Extract method | |
51 method = find(pl, 'method'); | |
52 | |
53 for jj = 1:numel(bs) | |
54 | |
55 % Diff can't work for cdata objects since we need x data | |
56 if isa(bs(jj).data, 'cdata') | |
57 end | |
58 | |
59 % Compute derivative with selected method | |
60 yu = bs(jj).data.yunits; | |
61 switch lower(method) | |
62 case 'trapezoidal' | |
63 if isa(bs(jj).data, 'cdata') | |
64 y = bs(jj).data.getY; | |
65 bs(jj).data = cdata(trapz(y)); | |
66 else | |
67 x = bs(jj).data.getX; | |
68 y = bs(jj).data.getY; | |
69 bs(jj).data = cdata(trapz(x,y)); | |
70 end | |
71 bs(jj).setYunits(yu); | |
72 otherwise | |
73 error('### Unknown method for computing the derivative.'); | |
74 end | |
75 | |
76 | |
77 % name for this object | |
78 bs(jj).name = sprintf('integrate(%s)', ao_invars{jj}); | |
79 % add history | |
80 bs(jj).addHistory(getInfo('None'), pl, ao_invars(jj), bs(jj).hist); | |
81 end | |
82 | |
83 % clear errors | |
84 bs.clearErrors; | |
85 | |
86 % Set output | |
87 if nargout == numel(bs) | |
88 % List of outputs | |
89 for ii = 1:numel(bs) | |
90 varargout{ii} = bs(ii); | |
91 end | |
92 else | |
93 % Single output | |
94 varargout{1} = bs; | |
95 end | |
96 end | |
97 | |
98 %-------------------------------------------------------------------------- | |
99 % Get Info Object | |
100 %-------------------------------------------------------------------------- | |
101 function ii = getInfo(varargin) | |
102 | |
103 if nargin == 1 && strcmpi(varargin{1}, 'None') | |
104 sets = {}; | |
105 pl = []; | |
106 else | |
107 sets = {'Default'}; | |
108 pl = getDefaultPlist; | |
109 end | |
110 % Build info object | |
111 ii = minfo(mfilename, 'ao', 'ltpda', utils.const.categories.sigproc, '$Id: integrate.m,v 1.11 2011/04/08 08:56:11 hewitson Exp $', sets, pl); | |
112 end | |
113 | |
114 %-------------------------------------------------------------------------- | |
115 % Get Default Plist | |
116 %-------------------------------------------------------------------------- | |
117 function plout = getDefaultPlist() | |
118 persistent pl; | |
119 if exist('pl', 'var')==0 || isempty(pl) | |
120 pl = buildplist(); | |
121 end | |
122 plout = pl; | |
123 end | |
124 | |
125 function pl = buildplist() | |
126 pl = plist(); | |
127 | |
128 % Method | |
129 p = param({'method',['The method to use. Choose between:<ul>', ... | |
130 '<li>''Trapezoidal'' - integration using MATLAB''s trapz function</li>', ... | |
131 '</ul>' ... | |
132 ]}, {1, {'Trapezoidal'}, paramValue.SINGLE}); | |
133 pl.append(p); | |
134 | |
135 end | |
136 |