comparison m-toolbox/classes/@ao/find.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 % FIND particular samples that satisfy the input query and return a new AO.
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %
4 % DESCRIPTION: FIND particular samples that satisfy the input query and return a new AO.
5 %
6 % CALL: b = find(a, 'x > 10 & x < 100')
7 % b = find(a, plist)
8 %
9 % PROCINFO: The selected indexes are stored in the procinfo of the
10 % output AO. You can get this indexes with:
11 % b.procinfo.find('index')
12 %
13 % <a href="matlab:utils.helper.displayMethodInfo('ao', 'find')">Parameters Description</a>
14 %
15 % VERSION: $Id: find.m,v 1.47 2011/10/05 12:04:25 ingo Exp $
16 %
17 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
18
19 function varargout = find(varargin)
20
21 % Check if this is a call for parameters
22 if utils.helper.isinfocall(varargin{:})
23 varargout{1} = getInfo(varargin{3});
24 return
25 end
26
27 import utils.const.*
28 utils.helper.msg(msg.PROC3, 'running %s/%s', mfilename('class'), mfilename);
29
30 % Collect input variable names
31 in_names = cell(size(varargin));
32 for ii = 1:nargin,in_names{ii} = inputname(ii);end
33
34 % Collect all AOs and plists
35 [as, ao_invars] = utils.helper.collect_objects(varargin(:), 'ao', in_names);
36 [pl, pl_invars, rest] = utils.helper.collect_objects(varargin(:), 'plist', in_names);
37
38 % Decide on a deep copy or a modify
39 bs = copy(as, nargout);
40
41 % combine plists
42 pl = parse(pl, getDefaultPlist());
43
44 % initialise queries
45 queries = '';
46 % extract any from inputs
47 for j=1:numel(rest)
48 if ischar(rest{j})
49 queries = [queries ' & ' rest{j}];
50 end
51 end
52
53 % Get sample selection from plist
54 queries = [queries ' & ' find(pl, 'query')];
55
56 % We may have pre or trailing '&' now
57 queries = strtrim(queries);
58 if queries(1) == '&'
59 queries = queries(2:end);
60 end
61 if queries(end) == '&'
62 queries = queries(1:end-1);
63 end
64
65 % store for history
66 queries = strtrim(queries);
67 pl.pset('query', queries);
68
69 % Loop over input AOs
70 for j=1:numel(bs)
71
72 % The user uses the variables x and y so we need
73 % to put them in the workspace.
74 clear x
75 if ~isa(bs(j).data, 'cdata')
76 x = bs(j).data.getX;
77 end
78 y = bs(j).data.getY;
79
80 idx = [];
81 cmd = sprintf('idx = find(%s);', queries);
82 try
83 eval(cmd);
84 catch ME
85 error('%s\n\n### please use x or y for the queries.',ME.message);
86 end
87
88 % set data
89 if ~isa(bs(j).data, 'cdata')
90 %%% tsdata, fsdata, xydata
91 bs(j).data.setXY(x(idx), y(idx));
92
93 % Set 'dx' and 'dy' and 'enbw'
94 if numel(bs(j).data.dx) > 1
95 bs(j).data.setDx(bs(j).data.dx(idx));
96 end
97 if numel(bs(j).data.dy) > 1
98 bs(j).data.setDy(bs(j).data.dy(idx));
99 end
100 if isprop(bs(j).data, 'enbw')
101 if numel(bs(j).data.enbw) > 1
102 bs(j).data.setEnbw(bs(j).data.enbw(idx));
103 end
104 end
105
106 else
107 %%% cdata
108 bs(j).data.setY(y(idx));
109 if numel(bs(j).data.dy) > 1
110 bs(j).data.setY(bs(j).data.dy(idx));
111 end
112 end
113
114 %%% Set special properties for 'tsdata' objects
115 if isa(bs(j).data, 'tsdata')
116 % Set the toffset to zero because the x-vector includes the toffset
117 bs(j).data.setToffset(0);
118
119 % Check fs and see if is x evenly sampled
120 [fs,t0,fitted] = tsdata.fitfs(x(idx));
121 if fitted
122 bs(j).data.setFs(fs);
123 bs(j).data.fixNsecs();
124 else
125 % drop x
126 bs(j).data.collapseX;
127 end
128 end
129
130 % set name
131 bs(j).name = sprintf('find(%s)', ao_invars{j});
132 % add history
133 bs(j).addHistory(getInfo('None'), pl, ao_invars(j), bs(j).hist);
134 bs(j).procinfo = plist('index', idx);
135 end
136
137 % Set output
138 if nargout == numel(bs)
139 % List of outputs
140 for ii = 1:numel(bs)
141 varargout{ii} = bs(ii);
142 end
143 else
144 % Single output
145 varargout{1} = bs;
146 end
147 end
148
149 %--------------------------------------------------------------------------
150 % Get Info Object
151 %--------------------------------------------------------------------------
152 function ii = getInfo(varargin)
153 if nargin == 1 && strcmpi(varargin{1}, 'None')
154 sets = {};
155 pls = [];
156 else
157 sets = {'Default'};
158 pls = getDefaultPlist;
159 end
160 % Build info object
161 ii = minfo(mfilename, 'ao', 'ltpda', utils.const.categories.helper, '$Id: find.m,v 1.47 2011/10/05 12:04:25 ingo Exp $', sets, pls);
162 end
163
164 %--------------------------------------------------------------------------
165 % Get Default Plist
166 %--------------------------------------------------------------------------
167 function plout = getDefaultPlist()
168 persistent pl;
169 if exist('pl', 'var')==0 || isempty(pl)
170 pl = buildplist();
171 end
172 plout = pl;
173 end
174
175 function pl = buildplist()
176 pl = plist({'query', 'A search string specifying a query on ''x'' or ''y'' (or ''vals'' for cdata). <br>For example, <tt>''x>3 & x<5''</tt>'}, paramValue.EMPTY_STRING);
177 end
178
179