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.13 2007/09/27 09:03:25 ingo Exp $

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

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

 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.13 2007/09/27 09:03:25 ingo 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 % HISTORY: 08-05-07 A Monsky
0029 %             Creation
0030 %
0031 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0032 
0033 VERSION  = '$Id: diag.m,v 1.13 2007/09/27 09:03:25 ingo Exp $';
0034 
0035 %% Check if this is a call for parameters
0036 
0037 if nargin == 2
0038   if isa(varargin{1}, 'ao') && ischar(varargin{2})
0039     in = char(varargin{2});
0040     if strcmp(in, 'Params')
0041       varargout{1} = getDefaultPL();
0042       return
0043     elseif strcmp(in, 'Version')
0044       varargout{1} = VERSION;
0045       return
0046     end
0047   end
0048 end
0049 
0050 %% capture input variable names
0051 invars = {};
0052 
0053 as = [];
0054 bs = [];
0055 pl = [];
0056 
0057 for j=1:nargin
0058   invars = [invars cellstr(inputname(j))];
0059   if isa(varargin{j}, 'ao')
0060     as = [as varargin{j}];
0061   end
0062   if isa(varargin{j}, 'plist')
0063     pl = [pl varargin{j}];
0064   end
0065 end
0066 
0067 if ~isempty (pl)
0068   pl = combine(pl);
0069 end
0070 
0071 
0072 %% go through analysis objects
0073 for j=1:numel(as)
0074   a = as(j);
0075 
0076   d = get(a, 'data');
0077   dinfo = whos('d');
0078 
0079   % Which data type do we have
0080   dtype = dinfo.class;
0081   switch dtype
0082 
0083     case 'cdata'
0084       disp('* DIAGONAL of cdata object');
0085       % make a new cdata object
0086       [h, c] = single_operation(d, 'diag',pl);
0087 
0088       % make output analysis object
0089       h = set(h, 'inhists', [a.hist]);
0090 
0091       %% Set the var_name to the history
0092       if (j <= nargin)
0093         if (isempty (inputname(j)))
0094           h = set(h, 'invars', cellstr('no var_name'));
0095         else
0096           h = set(h, 'invars', cellstr(inputname(j)));
0097         end
0098       else
0099         h = set(h, 'invars', cellstr('no var_name'));
0100       end
0101 
0102       b = ao(c, h);
0103       b = set(b, 'name',  sprintf('diag(%s)', char(invars{1})));
0104     case {'tsdata','fsdata','xydata'}
0105       error('### this function works for cdata type AO only')
0106     otherwise
0107       error('### unknown data type.')
0108   end
0109 
0110   % add to output
0111   bs = [bs b];
0112 end
0113 
0114 % Reshape the ouput to the same size of the input
0115 bs = reshape(bs, size(as));
0116 varargout{1} = bs;
0117 
0118 %% Get default params
0119 function plo = getDefaultPL()
0120 
0121 plo = plist();
0122 plo = append(plo, 'option', 0);
0123 
0124 % END

Generated on Fri 02-Nov-2007 19:39:27 by m2html © 2003