comparison m-toolbox/classes/@ao/mean.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 % MEAN computes the mean value of the data in the AO.
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %
4 % DESCRIPTION: MEAN computes the mean value of the data in the AO.
5 % The uncertainty is evaluated as the standard deviation of the mean.
6 %
7 % CALL: ao_out = mean(ao_in);
8 % ao_out = mean(ao_in, pl);
9 %
10 % <a href="matlab:utils.helper.displayMethodInfo('ao', 'mean')">Parameters Description</a>
11 %
12 % VERSION: $Id: mean.m,v 1.49 2011/04/19 18:48:11 ingo Exp $
13 %
14 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
15
16 function varargout = mean(varargin)
17
18 % Check if the method was called by another method
19 callerIsMethod = utils.helper.callerIsMethod;
20
21 % Settings
22 operatorName = 'mean';
23 dxFcn = [];
24
25 if callerIsMethod
26 in_names = {};
27 else
28 % Collect input variable names
29 in_names = cell(size(varargin));
30 for ii = 1:nargin,in_names{ii} = inputname(ii);end
31 end
32
33 % Here we are forced to collect objects so that we can check that each ao
34 % is the correct type for doing diag.
35 as = utils.helper.collect_objects(varargin(:), 'ao', in_names);
36
37 % We filter out the data3D objects here since we don't know what to do
38 % with them so far.
39 aos = [];
40 for kk=1:numel(as)
41 if isa(as(kk).data, 'data3D')
42 warning('!!! Skipping ao [%s] - %s can''t operate on data3D objects at the moment.', as(kk).name, operatorName);
43 else
44 aos = [aos as(kk)];
45 end
46 end
47 if isempty(aos) % try for getInfo
48 out = ao.applymethod(0, callerIsMethod, in_names, operatorName, dxFcn, @getInfo, @getDefaultPlist, varargin{:});
49 varargout{1} = out;
50 return
51 end
52
53 % Apply method to all AOs
54 nAos = numel(aos);
55 n = zeros(nAos,1);
56 dy= zeros(nAos,1);
57 for ii=1:nAos
58 n(ii) = numel(aos(ii).data.y);
59 dy(ii) = std(aos(ii).y)/sqrt(n(ii));
60 end
61
62 copyObjects = nargout>0;
63 [bs, pl] = ao.applymethod(copyObjects, callerIsMethod, in_names, operatorName, dxFcn, @getInfo, @getDefaultPlist, varargin{:});
64
65 if isa(bs, 'ao')
66 bs = fixAxisData(bs, pl);
67 for ii=1:numel(bs)
68 bs(ii).setDy(dy(ii));
69 end
70 end
71
72 % set outputs
73 varargout = utils.helper.setoutputs(nargout, bs);
74
75 end
76
77 %--------------------------------------------------------------------------
78 % Get Info Object
79 %--------------------------------------------------------------------------
80 function ii = getInfo(varargin)
81 ii = minfo.getInfoAxis(mfilename, @getDefaultPlist, varargin);
82 end
83
84 %--------------------------------------------------------------------------
85 % Get Default Plist
86 %--------------------------------------------------------------------------
87
88 function plout = getDefaultPlist(set)
89 persistent pl;
90 persistent lastset;
91 if ~exist('pl', 'var') || isempty(pl) || ~strcmp(lastset, set)
92 pl = buildplist(set);
93 lastset = set;
94 end
95 plout = pl;
96 end
97
98 function plout = buildplist(varargin)
99 plout = plist.getDefaultAxisPlist(varargin{:});
100 end