Mercurial > hg > ltpda
comparison m-toolbox/classes/@ao/sort.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 % SORT the values in the AO. | |
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3 % | |
4 % DESCRIPTION: SORT sorts the values in the input data. | |
5 % | |
6 % CALL: ao_out = sort(ao_in); | |
7 % ao_out = sort(ao1, pl1, ao_vector, ao_matrix, pl2); | |
8 % | |
9 % <a href="matlab:utils.helper.displayMethodInfo('ao', 'sort')">Parameters Description</a> | |
10 % | |
11 % VERSION: $Id: sort.m,v 1.24 2011/04/08 08:56:13 hewitson Exp $ | |
12 % | |
13 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
14 | |
15 function varargout = sort (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 import utils.const.* | |
24 utils.helper.msg(msg.PROC3, 'running %s/%s', mfilename('class'), mfilename); | |
25 | |
26 % Collect input variable names | |
27 in_names = cell(size(varargin)); | |
28 for ii = 1:nargin,in_names{ii} = inputname(ii);end | |
29 | |
30 % Collect all AOs | |
31 [as, ao_invars] = utils.helper.collect_objects(varargin(:), 'ao', in_names); | |
32 pl = utils.helper.collect_objects(varargin(:), 'plist', in_names); | |
33 | |
34 % Decide on a deep copy or a modify | |
35 bs = copy(as, nargout); | |
36 | |
37 % Combine plists | |
38 pl = parse(pl, getDefaultPlist); | |
39 | |
40 % Get parameters | |
41 sdir = find(pl, 'dir'); | |
42 dim = find(pl, 'dim'); | |
43 | |
44 %% go through analysis objects | |
45 for j=1:numel(bs) | |
46 % Sort values | |
47 switch lower(dim) | |
48 case 'x' | |
49 if isa(bs(j).data, 'cdata') | |
50 error('### Sort to the x-axis of an AO with cdata is not possible'); | |
51 end | |
52 [mx, idx] = sort(bs(j).data.getX, 1, sdir); | |
53 my = bs(j).data.y(idx); | |
54 case 'y' | |
55 [my, idx] = sort(bs(j).y, 1, sdir); | |
56 if ~isa(bs(j).data, 'cdata') | |
57 mx = bs(j).data.getX(idx); | |
58 end | |
59 otherwise | |
60 error('### can''t sort along dimension ''%s''.', dim); | |
61 end | |
62 | |
63 % Sort the error dx and dy and enbw | |
64 if isprop(bs(j).data, 'dx') | |
65 if numel(bs(j).data.dx) > 1 | |
66 mdx = bs(j).data.dx(idx); | |
67 else | |
68 mdx = bs(j).data.dx; | |
69 end | |
70 else | |
71 mdx = []; | |
72 end | |
73 if numel(bs(j).data.dy) > 1 | |
74 mdy = bs(j).data.dy(idx); | |
75 else | |
76 mdy = bs(j).data.dy; | |
77 end | |
78 if isprop(bs(j).data, 'enbw') | |
79 if numel(bs(j).data.enbw) > 1 | |
80 menbw = bs(j).data.enbw(idx); | |
81 else | |
82 menbw = bs(j).data.enbw; | |
83 end | |
84 else | |
85 menbw = []; | |
86 end | |
87 | |
88 % set new data | |
89 if ~isa(bs(j).data, 'cdata') | |
90 bs(j).data.setXY(mx,my); | |
91 else | |
92 bs(j).data.setY(my); | |
93 end | |
94 | |
95 % set new error | |
96 if ~isempty(mdx) | |
97 bs(j).data.setDx(mdx); | |
98 end | |
99 if ~isempty(mdy) | |
100 bs(j).data.setDy(mdy); | |
101 end | |
102 if ~isempty(menbw) | |
103 bs(j).data.setEnbw(menbw); | |
104 end | |
105 | |
106 % set data name | |
107 bs(j).name = sprintf('sort(%s)', ao_invars{j}); | |
108 % Add history | |
109 bs(j).addHistory(getInfo('None'), pl, ao_invars(j), bs(j).hist); | |
110 end | |
111 | |
112 % Set output | |
113 if nargout == numel(bs) | |
114 % List of outputs | |
115 for ii = 1:numel(bs) | |
116 varargout{ii} = bs(ii); | |
117 end | |
118 else | |
119 % Single output | |
120 varargout{1} = bs; | |
121 end | |
122 end | |
123 | |
124 %-------------------------------------------------------------------------- | |
125 % Get Info Object | |
126 %-------------------------------------------------------------------------- | |
127 function ii = getInfo(varargin) | |
128 if nargin == 1 && strcmpi(varargin{1}, 'None') | |
129 sets = {}; | |
130 pl = []; | |
131 else | |
132 sets = {'Default'}; | |
133 pl = getDefaultPlist; | |
134 end | |
135 % Build info object | |
136 ii = minfo(mfilename, 'ao', 'ltpda', utils.const.categories.op, '$Id: sort.m,v 1.24 2011/04/08 08:56:13 hewitson Exp $', sets, pl); | |
137 end | |
138 | |
139 %-------------------------------------------------------------------------- | |
140 % Get Default Plist | |
141 %-------------------------------------------------------------------------- | |
142 function plout = getDefaultPlist() | |
143 persistent pl; | |
144 if exist('pl', 'var')==0 || isempty(pl) | |
145 pl = buildplist(); | |
146 end | |
147 plout = pl; | |
148 end | |
149 | |
150 function pl = buildplist() | |
151 pl = plist(); | |
152 | |
153 % Dim | |
154 p = param({'dim', 'Sort on the specified axis.'}, {2, {'x', 'y'}, paramValue.SINGLE}); | |
155 pl.append(p); | |
156 | |
157 % Dir | |
158 p = param({'dir', 'Direction of sort.'}, {1, {'ascend', 'descend'}, paramValue.SINGLE}); | |
159 pl.append(p); | |
160 end | |
161 % END | |
162 | |
163 | |
164 % PARAMETERS: | |
165 % | |
166 % 'dim' - sort along the specified dimension: 'x' or 'y' | |
167 % [default: 'y'] | |
168 % 'dir' - select direction of sort: 'ascend' or 'descend' | |
169 % [default: 'ascend'] | |
170 % |