Mercurial > hg > ltpda
comparison m-toolbox/classes/@ao/dropduplicates.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 % DROPDUPLICATES drops all duplicate samples in time-series AOs. | |
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3 % | |
4 % DROPDUPLICATES drops all duplicate samples in time-series AOs. Duplicates | |
5 % are identified by having a two consecutive time stamps | |
6 % closer than a set tolerance. | |
7 % | |
8 % CALL: bs = dropduplicates(as) | |
9 % | |
10 % INPUTS: as - array of analysis objects | |
11 % pl - parameter list (see below) | |
12 % | |
13 % OUTPUTS: bs - array of analysis objects, one for each input | |
14 % | |
15 % <a href="matlab:utils.helper.displayMethodInfo('ao', 'dropduplicates')">Parameters Description</a> | |
16 % | |
17 % VERSION: $Id: dropduplicates.m,v 1.24 2011/04/08 08:56:13 hewitson Exp $ | |
18 % | |
19 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
20 | |
21 function varargout = dropduplicates(varargin) | |
22 | |
23 % Check if this is a call for parameters | |
24 if utils.helper.isinfocall(varargin{:}) | |
25 varargout{1} = getInfo(varargin{3}); | |
26 return | |
27 end | |
28 | |
29 import utils.const.* | |
30 utils.helper.msg(msg.PROC3, 'running %s/%s', mfilename('class'), mfilename); | |
31 | |
32 % Collect input variable names | |
33 in_names = cell(size(varargin)); | |
34 for ii = 1:nargin,in_names{ii} = inputname(ii);end | |
35 | |
36 % Collect all AOs | |
37 [as, ao_invars] = utils.helper.collect_objects(varargin(:), 'ao', in_names); | |
38 [pl, pl_invars] = utils.helper.collect_objects(varargin(:), 'plist', in_names); | |
39 | |
40 % Decide on a deep copy or a modify | |
41 bs = copy(as, nargout); | |
42 | |
43 % Combine plists | |
44 pl = parse(pl, getDefaultPlist); | |
45 | |
46 % Get tolerance | |
47 tol = find(pl, 'tol'); | |
48 | |
49 % Get only tsdata AOs | |
50 for j=1:numel(bs) | |
51 if isa(bs(j).data, 'tsdata') | |
52 d = abs(diff(bs(j).data.getX)); | |
53 idx = find(d<tol); | |
54 utils.helper.msg(msg.PROC1, 'found %d duplicate samples', numel(idx)); | |
55 % Wipe out x samples | |
56 if ~isempty(bs(j).data.x) | |
57 bs(j).data.x(idx) = []; | |
58 end | |
59 % Wipe out y samples | |
60 bs(j).data.y(idx) = []; | |
61 % Wipe out error | |
62 if numel(bs(j).data.dx) > 1 | |
63 bs(j).data.dx(idx) = []; | |
64 end | |
65 if numel(bs(j).data.dy) > 1 | |
66 bs(j).data.dy(idx) = []; | |
67 end | |
68 % set name | |
69 bs(j).name = sprintf('dropduplicates(%s)', ao_invars{j}); | |
70 % Add history | |
71 bs(j).addHistory(getInfo('None'), pl, ao_invars(j), bs(j).hist); | |
72 else | |
73 warning('!!! Skipping AO %s - it''s not a time-series AO.', ao_invars{j}); | |
74 bs(j) = []; | |
75 end | |
76 end | |
77 | |
78 % Set output | |
79 if nargout == numel(bs) | |
80 % List of outputs | |
81 for ii = 1:numel(bs) | |
82 varargout{ii} = bs(ii); | |
83 end | |
84 else | |
85 % Single output | |
86 varargout{1} = bs; | |
87 end | |
88 end | |
89 | |
90 %-------------------------------------------------------------------------- | |
91 % Get Info Object | |
92 %-------------------------------------------------------------------------- | |
93 function ii = getInfo(varargin) | |
94 if nargin == 1 && strcmpi(varargin{1}, 'None') | |
95 sets = {}; | |
96 pl = []; | |
97 else | |
98 sets = {'Default'}; | |
99 pl = getDefaultPlist; | |
100 end | |
101 % Build info object | |
102 ii = minfo(mfilename, 'ao', 'ltpda', utils.const.categories.sigproc, '$Id: dropduplicates.m,v 1.24 2011/04/08 08:56:13 hewitson Exp $', sets, pl); | |
103 end | |
104 | |
105 %-------------------------------------------------------------------------- | |
106 % Get Default Plist | |
107 %-------------------------------------------------------------------------- | |
108 | |
109 function plout = getDefaultPlist() | |
110 persistent pl; | |
111 if exist('pl', 'var')==0 || isempty(pl) | |
112 pl = buildplist(); | |
113 end | |
114 plout = pl; | |
115 end | |
116 | |
117 function pl = buildplist() | |
118 pl = plist(); | |
119 | |
120 % tol | |
121 p = param({'tol','The time interval tolerance to consider two consecutive samples as duplicates.'}, ... | |
122 {1, {5e-3}, paramValue.OPTIONAL}); | |
123 pl.append(p); | |
124 | |
125 end | |
126 | |
127 |