comparison m-toolbox/classes/@ao/select.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 % SELECT select particular samples from the input AOs and return new AOs with only those samples.
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %
4 % DESCRIPTION: SELECT select particular samples from the input AOs and return
5 % new AOs with only those samples.
6 %
7 % CALL: b = select(a, [1 2 3 4]);
8 % b = select(a, pl)
9 %
10 % <a href="matlab:utils.helper.displayMethodInfo('ao', 'select')">Parameters Description</a>
11 %
12 % VERSION: $Id: select.m,v 1.42 2011/10/06 05:21:05 hewitson Exp $
13 %
14 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
15
16 function varargout = select(varargin)
17
18 % Check if this is a call for parameters
19 if utils.helper.isinfocall(varargin{:})
20 varargout{1} = getInfo(varargin{3});
21 return
22 end
23
24 import utils.const.*
25 utils.helper.msg(msg.PROC3, 'running %s/%s', mfilename('class'), mfilename);
26
27 % Collect input variable names
28 in_names = cell(size(varargin));
29 for ii = 1:nargin,in_names{ii} = inputname(ii);end
30
31 % Collect all AOs and plists
32 [as, ao_invars, rest] = utils.helper.collect_objects(varargin(:), 'ao', in_names);
33 [pl, pl_invars, rest] = utils.helper.collect_objects(rest(:), 'plist', in_names);
34
35 % Decide on a deep copy or a modify
36 bs = copy(as, nargout);
37
38 % Combine plists
39 pl = parse(pl, getDefaultPlist);
40
41 % Check for samples in arguments
42 samples_in = [];
43 for jj = 1:numel(rest)
44 if isnumeric(rest{jj})
45 samples_in = [samples_in reshape(rest{jj}, 1, [])];
46 end
47 end
48
49 % Get sample selection from plist
50 sam = find(pl, 'samples');
51 axis = find(pl, 'axis');
52 if isnumeric(sam)
53 samples = [samples_in reshape(find(pl, 'samples'), 1, [])];
54 elseif isa(sam, 'ao')
55 if isa(sam.data, 'tsdata')
56 if axis == 'y'
57 samples = [samples_in sam.y];
58 else
59 samples = [samples_in 1:len(sam)];
60 end
61 elseif isa(sam.data, 'xydata') || isa(sam.data, 'fsdata')
62 if axis == 'y'
63 samples = [samples_in reshape(sam.y, 1, [])];
64 else
65 samples = [samples_in reshape(sam.x, 1, [])];
66 end
67 end
68 end
69 samples = sort(samples);
70 % Set the samples again to the plist because it is possible that the user
71 % specified the not in the plist but direct as input.
72 if ~isempty(samples_in)
73 pl.pset('samples', samples);
74 end
75
76 % Loop over input AOs
77 for jj = 1:numel(bs)
78 if isa(bs(jj).data, 'cdata')
79 bs(jj).data.setY(bs(jj).data.y(samples));
80 if numel(bs(jj).data.dy) > 1
81 bs(jj).data.setDy(bs(jj).data.dy(samples));
82 end
83 if isprop(bs(jj).data, 'enbw')
84 if numel(bs(jj).data.enbw) > 1
85 bs(jj).data.setEnbw(bs(jj).data.enbw(samples));
86 end
87 end
88 else
89 % Get x
90 x = bs(jj).data.getX;
91 % set new samples
92 bs(jj).data.setXY(x(samples), bs(jj).data.y(samples));
93 if numel(bs(jj).data.dx) > 1
94 bs(jj).data.setDx(bs(jj).data.dx(samples));
95 end
96 if numel(bs(jj).data.dy) > 1
97 bs(jj).data.setDy(bs(jj).data.dy(samples));
98 end
99 if isprop(bs(jj).data, 'enbw')
100 if numel(bs(jj).data.enbw) > 1
101 bs(jj).data.setEnbw(bs(jj).data.enbw(samples));
102 end
103 end
104 % if this is tsdata, we may need to do some other steps
105 if isa(bs(jj).data, 'tsdata')
106 % recompute nsecs
107 bs(jj).data.fixNsecs;
108 end
109 end
110 % Set AO name
111 bs(jj).name = sprintf('select(%s)', ao_invars{jj});
112 % Add history
113 bs(jj).addHistory(getInfo('None'), pl, ao_invars(jj), bs(jj).hist);
114 end
115
116 % Set output
117 varargout = utils.helper.setoutputs(nargout, bs);
118
119 end
120
121 %--------------------------------------------------------------------------
122 % Get Info Object
123 %--------------------------------------------------------------------------
124 function ii = getInfo(varargin)
125 if nargin == 1 && strcmpi(varargin{1}, 'None')
126 sets = {};
127 pl = [];
128 else
129 sets = {'Default'};
130 pl = getDefaultPlist();
131 end
132 % Build info object
133 ii = minfo(mfilename, 'ao', 'ltpda', utils.const.categories.sigproc, '$Id: select.m,v 1.42 2011/10/06 05:21:05 hewitson Exp $', sets, pl);
134 end
135
136 %--------------------------------------------------------------------------
137 % Get Default Plist
138 %--------------------------------------------------------------------------
139 function plout = getDefaultPlist()
140 persistent pl;
141 if ~exist('pl', 'var') || isempty(pl)
142 pl = buildplist();
143 end
144 plout = pl;
145 end
146
147 function plo = buildplist()
148 plo = plist();
149
150 p = param({'samples', 'A list of samples to select.'}, paramValue.EMPTY_DOUBLE);
151 plo.append(p);
152
153 p = param({'axis', 'If the samples are specified with an AO then it is possible from axis you want to select the samples.'}, {1 {'x', 'y'} paramValue.SINGLE});
154 plo.append(p);
155
156 end
157
158 % END
159 % PARAMETERS: 'samples' - a list of samples to select
160 %