view m-toolbox/classes/@ao/mean.m @ 44:409a22968d5e
default
Add unit tests
author
Daniele Nicolodi <nicolodi@science.unitn.it>
date
Tue, 06 Dec 2011 18:42:11 +0100 (2011-12-06)
parents
f0afece42f48
children
line source
+ − % MEAN computes the mean value of the data in the AO.
+ − %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+ − %
+ − % DESCRIPTION: MEAN computes the mean value of the data in the AO.
+ − % The uncertainty is evaluated as the standard deviation of the mean.
+ − %
+ − % CALL: ao_out = mean(ao_in);
+ − % ao_out = mean(ao_in, pl);
+ − %
+ − % <a href="matlab:utils.helper.displayMethodInfo('ao', 'mean')">Parameters Description</a>
+ − %
+ − % VERSION: $Id: mean.m,v 1.49 2011/04/19 18:48:11 ingo Exp $
+ − %
+ − %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+ −
+ − function varargout = mean(varargin)
+ −
+ − % Check if the method was called by another method
+ − callerIsMethod = utils.helper.callerIsMethod;
+ −
+ − % Settings
+ − operatorName = 'mean';
+ − dxFcn = [];
+ −
+ − if callerIsMethod
+ − in_names = {};
+ − else
+ − % Collect input variable names
+ − in_names = cell(size(varargin));
+ − for ii = 1:nargin,in_names{ii} = inputname(ii);end
+ − end
+ −
+ − % Here we are forced to collect objects so that we can check that each ao
+ − % is the correct type for doing diag.
+ − as = utils.helper.collect_objects(varargin(:), 'ao', in_names);
+ −
+ − % We filter out the data3D objects here since we don't know what to do
+ − % with them so far.
+ − aos = [];
+ − for kk=1:numel(as)
+ − if isa(as(kk).data, 'data3D')
+ − warning('!!! Skipping ao [%s] - %s can''t operate on data3D objects at the moment.', as(kk).name, operatorName);
+ − else
+ − aos = [aos as(kk)];
+ − end
+ − end
+ − if isempty(aos) % try for getInfo
+ − out = ao.applymethod(0, callerIsMethod, in_names, operatorName, dxFcn, @getInfo, @getDefaultPlist, varargin{:});
+ − varargout{1} = out;
+ − return
+ − end
+ −
+ − % Apply method to all AOs
+ − nAos = numel(aos);
+ − n = zeros(nAos,1);
+ − dy= zeros(nAos,1);
+ − for ii=1:nAos
+ − n(ii) = numel(aos(ii).data.y);
+ − dy(ii) = std(aos(ii).y)/sqrt(n(ii));
+ − end
+ −
+ − copyObjects = nargout>0;
+ − [bs, pl] = ao.applymethod(copyObjects, callerIsMethod, in_names, operatorName, dxFcn, @getInfo, @getDefaultPlist, varargin{:});
+ −
+ − if isa(bs, 'ao')
+ − bs = fixAxisData(bs, pl);
+ − for ii=1:numel(bs)
+ − bs(ii).setDy(dy(ii));
+ − end
+ − end
+ −
+ − % set outputs
+ − varargout = utils.helper.setoutputs(nargout, bs);
+ −
+ − end
+ −
+ − %--------------------------------------------------------------------------
+ − % Get Info Object
+ − %--------------------------------------------------------------------------
+ − function ii = getInfo(varargin)
+ − ii = minfo.getInfoAxis(mfilename, @getDefaultPlist, varargin);
+ − end
+ −
+ − %--------------------------------------------------------------------------
+ − % Get Default Plist
+ − %--------------------------------------------------------------------------
+ −
+ − function plout = getDefaultPlist(set)
+ − persistent pl;
+ − persistent lastset;
+ − if ~exist('pl', 'var') || isempty(pl) || ~strcmp(lastset, set)
+ − pl = buildplist(set);
+ − lastset = set;
+ − end
+ − plout = pl;
+ − end
+ −
+ − function plout = buildplist(varargin)
+ − plout = plist.getDefaultAxisPlist(varargin{:});
+ − end