Home > classes > @ao > var.m

var

PURPOSE ^

VAR overloads the var operator for Analysis objects. Compute the variance.

SYNOPSIS ^

function ao_out = var (varargin)

DESCRIPTION ^

 VAR overloads the var operator for Analysis objects. Compute the variance.

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

 DESCRIPTION: VAR overloads the var operator for Analysis objects.
              Compute the variance.
              VAR(ao) is the variance of the values in ao.data.

 CALL: ao_out = var(ao_in);
       ao_out = var(ao_in, dim);
       ao_out = var(ao_in, W, DIM); --> use the parameterlist
       ao_out = var(ao_in, pl);
       ao_out = var(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>
                   'W'               []             represent the weight vector W
                  'dim'          1 or 2 or 3 ...    takes the var along the
                                                    dimension dim
                          tsdata  fsdata  xydata
                 'xdata'   't'     'f'      'x'     compute the var of the x-axis
                 'ydata'   'x'     'xx'     'y'     compute the var of the y-axis

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

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

 HISTORY: 23-05-2007 Diepholz
             Creation

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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function ao_out = var (varargin)
0002 % VAR overloads the var operator for Analysis objects. Compute the variance.
0003 %
0004 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0005 %
0006 % DESCRIPTION: VAR overloads the var operator for Analysis objects.
0007 %              Compute the variance.
0008 %              VAR(ao) is the variance of the values in ao.data.
0009 %
0010 % CALL: ao_out = var(ao_in);
0011 %       ao_out = var(ao_in, dim);
0012 %       ao_out = var(ao_in, W, DIM); --> use the parameterlist
0013 %       ao_out = var(ao_in, pl);
0014 %       ao_out = var(ao1, pl1, ao_vector, ao_matrix, pl2);
0015 %
0016 % POSSIBLE VALUES: ao_in  = [ao2 ao3]
0017 %                  ao_in  = ao_vector
0018 %                  ao_in  = ao_matrix
0019 %
0020 % PARAMETER LIST:  <key>           <value>             <description>
0021 %                   'W'               []             represent the weight vector W
0022 %                  'dim'          1 or 2 or 3 ...    takes the var along the
0023 %                                                    dimension dim
0024 %                          tsdata  fsdata  xydata
0025 %                 'xdata'   't'     'f'      'x'     compute the var of the x-axis
0026 %                 'ydata'   'x'     'xx'     'y'     compute the var of the y-axis
0027 %
0028 % The following call returns a parameter list object that contains the
0029 % default parameter values:
0030 %
0031 % >> pl = var(ao, 'Params')
0032 %
0033 % HISTORY: 23-05-2007 Diepholz
0034 %             Creation
0035 %
0036 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0037 
0038 ALGONAME = mfilename;
0039 VERSION  = '$Id: var.m,v 1.4 2007/06/22 08:32:49 ingo Exp $';
0040 ao_out   = [];
0041 pl       = plist();
0042 option   = '';
0043 
0044 %% Check if this is a call for parameters
0045 if nargin == 2
0046   if isa(varargin{1}, 'ao') && ischar(varargin{2})
0047     in = char(varargin{2});
0048     if strcmp(in, 'Params')
0049       ao_out = getDefaultPL();
0050       return
0051     end
0052   end
0053 end
0054 
0055 %% store the input ao's in the vector: ao_set
0056 ao_set = [];
0057 for i=1:nargin
0058   a = varargin{i};
0059   if isa(a, 'ao')
0060     [m,n] = size(a);
0061     for i = 1:m
0062       for j = 1:n
0063         ao_set  = [ao_set a(i,j)];
0064       end
0065     end
0066   elseif isa(varargin{i}, 'plist')
0067     pl = [pl varargin{i}];
0068   elseif isnumeric(varargin{i})
0069     pl = [pl plist(param('dim', varargin{i}))];
0070   end
0071 end
0072 
0073 if ~isempty (pl)
0074   pl = combine(pl);
0075 end
0076 
0077 %% go through analysis objects
0078 for j=1:length(ao_set)
0079   a = ao_set(j);
0080 
0081   [h, var_data] = single_operation(a.data, 'var', pl);
0082 
0083   %% Add the history from the ao object to the history
0084   h = set(h, 'inhists', [a.hist]);
0085 
0086   %% Set the var_name to the history
0087   if (j <= nargin)
0088     if (isempty (inputname(j)))
0089       h = set(h, 'invars', cellstr('no var_name'));
0090     else
0091       h = set(h, 'invars', cellstr(inputname(j)));
0092     end
0093   else
0094     h = set(h, 'invars', cellstr('no var_name'));
0095   end
0096 
0097   % convert to cdata type
0098   var_x    = [];
0099   var_y    = [];
0100 
0101   do_xdata = find(pl, 'xdata');
0102   do_ydata = find(pl, 'ydata');
0103 
0104   %% Is no axis entry in the parameter list
0105   %% then set the default axis = xdata
0106   if isempty(do_xdata) && isempty(do_ydata)
0107     do_ydata = 'yes';
0108   end
0109 
0110   %% Get the operation result. It is stored in the individual axis
0111   pl_get_axis = plist([param('xdata', do_xdata) param('ydata', do_ydata)]);
0112   [var_x, var_y] = get_xy_axis(var_data, pl_get_axis);
0113 
0114   var_cdata = cdata([var_x var_y]);
0115   var_cdata = set (var_cdata, 'name', var_data.name);
0116   var_cdata = set (var_cdata, 'xunits', var_data.xunits);
0117   var_cdata = set (var_cdata, 'yunits', var_data.yunits);
0118 
0119   %% create a new analysis objects
0120   new_ao = a;
0121   new_ao = ao  (var_cdata, h);
0122   new_ao = set (new_ao, 'name', sprintf('var(%s)',a.name) );
0123 
0124   ao_out = [ao_out new_ao];
0125 
0126 end
0127 
0128 %% Get default params
0129 function pl_default = getDefaultPL()
0130 
0131 disp('* creating default plist...');
0132   pl_default = plist([param('dim',    '')
0133                       param('W',      [])
0134                       param('xdata',  '')
0135                       param('ydata',  '')]);
0136 disp('* done.');
0137 
0138 % END

Generated on Mon 03-Sep-2007 12:12:34 by m2html © 2003