Home > classes > @ao > diag.m

diag

PURPOSE ^

DIAG overloads the diagonal operator for Analysis Objects.

SYNOPSIS ^

function varargout = diag(varargin)

DESCRIPTION ^

 DIAG overloads the diagonal operator for Analysis Objects.

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

 DESCRIPTION: DIAG overloads the diagonal operator for Analysis Objects.

 CALL:        b = diag (a)    % only with data = cdata
              b = diag (a, pl)

 INPUTS:      a  -  input analysis object
              pl - parameter list

 OUTPUTS:     b  - output analysis object

 Parameters:  'dim' - The value of the dimension must be zero or a positiv
                      number.
                      e.g. pl = plist('dim', 1); This parameter list computes
                      the first 'sub' diagonal.

 VERSION:     $Id: diag.m,v 1.19 2008/02/12 08:31:45 mauro Exp $

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

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

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

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

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

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

 HISTORY: 08-05-07 A Monsky
             Creation

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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function varargout = diag(varargin)
0002 % DIAG overloads the diagonal operator for Analysis Objects.
0003 %
0004 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0005 %
0006 % DESCRIPTION: DIAG overloads the diagonal operator for Analysis Objects.
0007 %
0008 % CALL:        b = diag (a)    % only with data = cdata
0009 %              b = diag (a, pl)
0010 %
0011 % INPUTS:      a  -  input analysis object
0012 %              pl - parameter list
0013 %
0014 % OUTPUTS:     b  - output analysis object
0015 %
0016 % Parameters:  'dim' - The value of the dimension must be zero or a positiv
0017 %                      number.
0018 %                      e.g. pl = plist('dim', 1); This parameter list computes
0019 %                      the first 'sub' diagonal.
0020 %
0021 % VERSION:     $Id: diag.m,v 1.19 2008/02/12 08:31:45 mauro Exp $
0022 %
0023 % The following call returns a parameter list object that contains the
0024 % default parameter values:
0025 %
0026 % >> pl = diag(ao, 'Params')
0027 %
0028 % The following call returns a string that contains the routine CVS version:
0029 %
0030 % >> version = diag(ao,'Version')
0031 %
0032 % The following call returns a string that contains the routine category:
0033 %
0034 % >> category = diag(ao,'Category')
0035 %
0036 % HISTORY: 08-05-07 A Monsky
0037 %             Creation
0038 %
0039 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0040 
0041 VERSION  = '$Id: diag.m,v 1.19 2008/02/12 08:31:45 mauro Exp $';
0042 CATEGORY = 'Operator';
0043 
0044 %% Check if this is a call for parameters
0045 
0046 if nargin == 2
0047   if isa(varargin{1}, 'ao') && ischar(varargin{2})
0048     in = char(varargin{2});
0049     if strcmp(in, 'Params')
0050       varargout{1} = getDefaultPL();
0051       return
0052     elseif strcmp(in, 'Version')
0053       varargout{1} = VERSION;
0054       return
0055     elseif strcmp(in, 'Category')
0056       varargout{1} = CATEGORY;
0057       return
0058     end
0059   end
0060 end
0061 
0062 %% capture input variable names
0063 invars = {};
0064 
0065 as = [];
0066 bs = [];
0067 pl = [];
0068 
0069 for j=1:nargin
0070   if isa(varargin{j}, 'ao')
0071     as = [as varargin{j}];
0072 
0073     % Memorise the variable name of the corresponding analysis object.
0074     % If the ao is an array or vector add the index to the variable name
0075     if numel(varargin{j}) == 1
0076       invars{end+1} = inputname(j);
0077     else
0078       for ii=1:numel(varargin{j})
0079         [I,J] = ind2sub(size(varargin{j}),ii);
0080         invars{end+1} = sprintf('%s(%d,%d)', inputname(j), I, J);
0081       end
0082     end
0083   end
0084   if isa(varargin{j}, 'plist')
0085     pl = [pl varargin{j}];
0086   end
0087 end
0088 
0089 if ~isempty (pl)
0090   pl = combine(pl);
0091 end
0092 
0093 
0094 %% go through analysis objects
0095 for j=1:numel(as)
0096   a = as(j);
0097 
0098   d = get(a, 'data');
0099   dinfo = whos('d');
0100 
0101   % Which data type do we have
0102   dtype = dinfo.class;
0103   switch dtype
0104 
0105     case 'cdata'
0106       %disp('* DIAGONAL of cdata object');
0107       % make a new cdata object
0108       [h, c] = single_operation(d, 'diag',pl);
0109 
0110       % make output analysis object
0111       h = set(h, 'inhists', [a.hist]);
0112 
0113       h = set(h, 'invars', cellstr(invars{j}));
0114 
0115       b = ao(c, h);
0116 
0117       b = setnh(b, 'name',  sprintf('diag(%s)', invars{j}));
0118 
0119     case {'tsdata','fsdata','xydata'}
0120       error('### this function works for cdata type AO only')
0121     otherwise
0122       error('### unknown data type.')
0123   end
0124 
0125   % add to output
0126   bs = [bs b];
0127 end
0128 
0129 % Reshape the ouput to the same size of the input
0130 bs = reshape(bs, size(as));
0131 varargout{1} = bs;
0132 
0133 %% Get default params
0134 function plo = getDefaultPL()
0135 
0136 plo = plist();
0137 plo = append(plo, 'option', 0);
0138 
0139 % END

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