


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.17 2008/01/10 20:00:29 hewitson 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
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


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.17 2008/01/10 20:00:29 hewitson 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.17 2008/01/10 20:00:29 hewitson 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 if isa(varargin{j}, 'ao') 0059 as = [as varargin{j}]; 0060 0061 % Memorise the variable name of the corresponding analysis object. 0062 % If the ao is an array or vector add the index to the variable name 0063 if numel(varargin{j}) == 1 0064 invars{end+1} = inputname(j); 0065 else 0066 for ii=1:numel(varargin{j}) 0067 [I,J] = ind2sub(size(varargin{j}),ii); 0068 invars{end+1} = sprintf('%s(%d,%d)', inputname(j), I, J); 0069 end 0070 end 0071 end 0072 if isa(varargin{j}, 'plist') 0073 pl = [pl varargin{j}]; 0074 end 0075 end 0076 0077 if ~isempty (pl) 0078 pl = combine(pl); 0079 end 0080 0081 0082 %% go through analysis objects 0083 for j=1:numel(as) 0084 a = as(j); 0085 0086 d = get(a, 'data'); 0087 dinfo = whos('d'); 0088 0089 % Which data type do we have 0090 dtype = dinfo.class; 0091 switch dtype 0092 0093 case 'cdata' 0094 %disp('* DIAGONAL of cdata object'); 0095 % make a new cdata object 0096 [h, c] = single_operation(d, 'diag',pl); 0097 0098 % make output analysis object 0099 h = set(h, 'inhists', [a.hist]); 0100 0101 h = set(h, 'invars', cellstr(invars{j})); 0102 0103 b = ao(c, h); 0104 0105 b = setnh(b, 'name', sprintf('diag(%s)', invars{j})); 0106 0107 case {'tsdata','fsdata','xydata'} 0108 error('### this function works for cdata type AO only') 0109 otherwise 0110 error('### unknown data type.') 0111 end 0112 0113 % add to output 0114 bs = [bs b]; 0115 end 0116 0117 % Reshape the ouput to the same size of the input 0118 bs = reshape(bs, size(as)); 0119 varargout{1} = bs; 0120 0121 %% Get default params 0122 function plo = getDefaultPL() 0123 0124 plo = plist(); 0125 plo = append(plo, 'option', 0); 0126 0127 % END