Mercurial > hg > ltpda
comparison m-toolbox/classes/@ao/max.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 % MAX computes the maximum value of the data in the AO. | |
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3 % | |
4 % DESCRIPTION: MAX computes the maximum value of the data in the AO. | |
5 % | |
6 % CALL: ao_out = max(ao_in); | |
7 % ao_out = max(ao_in, pl); | |
8 % | |
9 % NOTE: this does not currently work for data3D AOs. | |
10 % | |
11 % PARAMETERS: | |
12 % | |
13 % <a href="matlab:utils.helper.displayMethodInfo('ao', 'max')">Parameters Description</a> | |
14 % | |
15 % VERSION: $Id: max.m,v 1.30 2011/04/08 08:56:16 hewitson Exp $ | |
16 % | |
17 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
18 | |
19 function varargout = max(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 % 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 | |
32 [as, ao_invars] = utils.helper.collect_objects(varargin(:), 'ao', in_names); | |
33 pl = utils.helper.collect_objects(varargin(:), 'plist'); | |
34 | |
35 pl = combine(pl, getDefaultPlist); | |
36 | |
37 % Decide on a deep copy or a modify | |
38 bs = copy(as, nargout); | |
39 | |
40 | |
41 % Apply method to all AOs | |
42 for j=1:numel(bs) | |
43 skip = false; | |
44 % get max value | |
45 if isa(bs(j).data, 'data3D') | |
46 skip = true; | |
47 warning('!!! Skipping AO [%s]: max doesn''t work for 3D data at the moment', bs(j).name); | |
48 elseif isa(bs(j).data, 'data2D') | |
49 switch lower(find(pl, 'axis')) | |
50 case 'x' | |
51 [mx, idx] = max(bs(j).data.getX); | |
52 my = bs(j).data.getY(idx); | |
53 case 'y' | |
54 [my, idx] = max(bs(j).data.getY); | |
55 mx = bs(j).data.getX(idx); | |
56 otherwise | |
57 error('### The axis must one of ''x'' or ''y''.'); | |
58 end | |
59 d = xydata(mx, my); | |
60 d.xunits = bs(j).data.xunits; | |
61 d.yunits = bs(j).data.yunits; | |
62 bs(j).data = d; | |
63 else | |
64 my = max(bs(j).data.getY); | |
65 bs(j).data.setY(my); | |
66 end | |
67 | |
68 if ~skip | |
69 % Set new AO name | |
70 bs(j).name = ['max(' ao_invars{j} ')']; | |
71 % append history | |
72 bs(j).addHistory(getInfo('None'), pl, ao_invars(j), bs(j).hist); | |
73 % clear errors | |
74 bs(j).clearErrors(pl); | |
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.op, '$Id: max.m,v 1.30 2011/04/08 08:56:16 hewitson Exp $', sets, pl); | |
103 end | |
104 | |
105 %-------------------------------------------------------------------------- | |
106 % Get Default Plist | |
107 %-------------------------------------------------------------------------- | |
108 function plout = getDefaultPlist() | |
109 persistent pl; | |
110 if exist('pl', 'var')==0 || isempty(pl) | |
111 pl = buildplist(); | |
112 end | |
113 plout = pl; | |
114 end | |
115 | |
116 function pl = buildplist() | |
117 pl = plist.AXIS_2D_PLIST; | |
118 end | |
119 | |
120 % END |