Home > classes > @ao > sum.m

sum

PURPOSE ^

SUM overloads the sum operator for Analysis objects. Compute the sum value.

SYNOPSIS ^

function ao_out = sum (varargin)

DESCRIPTION ^

 SUM overloads the sum operator for Analysis objects. Compute the sum value.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

 DESCRIPTION: SUM overloads the sum operator for Analysis objects.
              Compute the sum value.
              SUM(ao) is the sum value of the elements in ao.data.

 CALL: ao_out = sum(ao_in);
       ao_out = sum(ao_in, dim);
       ao_out = sum(ao_in, pl);
       ao_out = sum(ao1, pl1, ao_vector, ao_matrix, pl2);

 POSSIBLE VALUES: ao_in  = [ao2 ao3]
                  ao_in  = ao_vector
                  ao_in  = ao_matrix

 PARAMETER LIST:  <key>           <value>             <description>
                  'dim'          1 or 2 or 3 ...    takes the sum along the
                                                    dimension dim
                          tsdata  fsdata  xydata
                 'xdata'   't'     'f'      'x'     compute the sum of the x-axis
                 'ydata'   'x'     'xx'     'y'     compute the sum of the y-axis

 The following call returns a parameter list object that contains the
 default parameter values:

 >> pl = sum(ao,'Params')

 The following call returns a string that contains the routine CVS version:

 >> version = sum(ao,'Version')

 The following call returns a string that contains the routine category:

 >> category = sum(ao,'Category')

 HISTORY: 25-05-2007 Diepholz
             Creation

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function ao_out = sum (varargin)
0002 % SUM overloads the sum operator for Analysis objects. Compute the sum value.
0003 %
0004 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0005 %
0006 % DESCRIPTION: SUM overloads the sum operator for Analysis objects.
0007 %              Compute the sum value.
0008 %              SUM(ao) is the sum value of the elements in ao.data.
0009 %
0010 % CALL: ao_out = sum(ao_in);
0011 %       ao_out = sum(ao_in, dim);
0012 %       ao_out = sum(ao_in, pl);
0013 %       ao_out = sum(ao1, pl1, ao_vector, ao_matrix, pl2);
0014 %
0015 % POSSIBLE VALUES: ao_in  = [ao2 ao3]
0016 %                  ao_in  = ao_vector
0017 %                  ao_in  = ao_matrix
0018 %
0019 % PARAMETER LIST:  <key>           <value>             <description>
0020 %                  'dim'          1 or 2 or 3 ...    takes the sum along the
0021 %                                                    dimension dim
0022 %                          tsdata  fsdata  xydata
0023 %                 'xdata'   't'     'f'      'x'     compute the sum of the x-axis
0024 %                 'ydata'   'x'     'xx'     'y'     compute the sum of the y-axis
0025 %
0026 % The following call returns a parameter list object that contains the
0027 % default parameter values:
0028 %
0029 % >> pl = sum(ao,'Params')
0030 %
0031 % The following call returns a string that contains the routine CVS version:
0032 %
0033 % >> version = sum(ao,'Version')
0034 %
0035 % The following call returns a string that contains the routine category:
0036 %
0037 % >> category = sum(ao,'Category')
0038 %
0039 % HISTORY: 25-05-2007 Diepholz
0040 %             Creation
0041 %
0042 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0043 
0044 VERSION  = '$Id: sum.m,v 1.9 2008/02/19 14:15:34 ingo Exp $';
0045 CATEGORY = 'Operator';
0046 
0047 ao_out   = [];
0048 
0049 % Check if this is a call for parameters
0050 if nargin == 2
0051   if isa(varargin{1}, 'ao') && ischar(varargin{2})
0052     in = char(varargin{2});
0053     if strcmp(in, 'Params')
0054       ao_out = getDefaultPL();
0055       return
0056     elseif strcmp(in, 'Version')
0057       ao_out = VERSION;
0058       return
0059     elseif strcmp(in, 'Category')
0060       ao_out = CATEGORY;
0061       return
0062     end
0063   end
0064 end
0065 
0066 %% Collect input ao's, plist's and ao variable names
0067 in_names = {};
0068 ps       = plist();
0069 for ii = 1:nargin
0070   in_names{end+1} = inputname(ii);
0071 
0072   if isnumeric(varargin{ii})
0073     ps = [ps plist(param('dim', varargin{ii}))];
0074   end
0075 end
0076 
0077 [ao_set, pl, invars] = collect_inputs(varargin, in_names);
0078 
0079 pl = combine(pl, ps);
0080 
0081 %% go through analysis objects
0082 for j=1:numel(ao_set)
0083   a = ao_set(j);
0084 
0085   [h, sum_data] = single_operation(a.data, 'sum', pl);
0086 
0087   %% Add the history from the ao object to the history
0088   h = set(h, 'inhists', [a.hist]);
0089 
0090   %% Set the var_name to the history
0091   h = set(h, 'invars', cellstr(invars{j}));
0092 
0093   do_xdata = find(pl, 'xdata');
0094   do_ydata = find(pl, 'ydata');
0095 
0096   %% Is no axis entry in the parameter list
0097   %% then set the default axis = xdata
0098   if isempty(do_xdata) && isempty(do_ydata)
0099     do_ydata = 'yes';
0100   end
0101 
0102   %% Get the operation result. It is stored in the individual axis
0103   pl_get_axis = plist([param('xdata', do_xdata) param('ydata', do_ydata)]);
0104   [sum_x, sum_y] = get_xy_values(sum_data, pl_get_axis);
0105 
0106   if ~isempty(do_xdata) && ~isempty(do_ydata)
0107     sum_cdata = cdata([sum_x sum_y]);
0108   elseif ~isempty(do_xdata)
0109     sum_cdata = cdata(sum_x);
0110   else
0111     sum_cdata = cdata(sum_y);
0112   end
0113 
0114   sum_cdata = set (sum_cdata, 'name', sum_data.name);
0115   sum_cdata = set (sum_cdata, 'xunits', sum_data.xunits);
0116   sum_cdata = set (sum_cdata, 'yunits', sum_data.yunits);
0117 
0118   %% create a new analysis objects
0119   new_ao = a;
0120   new_ao = ao  (sum_cdata, h);
0121   new_ao = setnh(new_ao, 'name', sprintf('sum(%s)',invars{j}) );
0122 
0123   ao_out = [ao_out new_ao];
0124 
0125 end
0126 
0127 % Reshape the ouput to the same size of the input
0128 ao_out = reshape(ao_out, size(ao_set));
0129 
0130 %% Get default params
0131 function plo = getDefaultPL()
0132 
0133 plo = plist();
0134 plo = append(plo, param('xdata', ''));
0135 plo = append(plo, param('ydata', ''));
0136 plo = append(plo, param('dim',   []));
0137 
0138 
0139 % END

Generated on Mon 31-Mar-2008 13:54:54 by m2html © 2003