Home > classes > @ao > inv.m

inv

PURPOSE ^

INV overloads the inverse function for Analysis Objects.

SYNOPSIS ^

function varargout = inv(varargin)

DESCRIPTION ^

 INV overloads the inverse function for Analysis Objects.

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

 DESCRIPTION: INV overloads the inverse function for Analysis Objects.

 CALL:        a = inv(a1)   % only with data = cdata

 VERSION:     $Id: inv.m,v 1.14 2008/01/20 12:53:30 hewitson Exp $

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

 >> pl = inv(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 = inv(varargin)
0002 % INV overloads the inverse function for Analysis Objects.
0003 %
0004 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0005 %
0006 % DESCRIPTION: INV overloads the inverse function for Analysis Objects.
0007 %
0008 % CALL:        a = inv(a1)   % only with data = cdata
0009 %
0010 % VERSION:     $Id: inv.m,v 1.14 2008/01/20 12:53:30 hewitson Exp $
0011 %
0012 % The following call returns a parameter list object that contains the
0013 % default parameter values:
0014 %
0015 % >> pl = inv(ao, 'Params')
0016 %
0017 % HISTORY: 08-05-07 A Monsky
0018 %             Creation
0019 %
0020 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0021 
0022 VERSION = '$Id: inv.m,v 1.14 2008/01/20 12:53:30 hewitson Exp $';
0023 bs      = [];
0024 
0025 %% Check if this is a call for parameters
0026 
0027 if nargin == 2
0028   if isa(varargin{1}, 'ao') && ischar(varargin{2})
0029     in = char(varargin{2});
0030     if strcmp(in, 'Params')
0031       varargout{1} = getDefaultPL();
0032       return
0033     elseif strcmp(in, 'Version')
0034       varargout{1} = VERSION;
0035       return
0036     end
0037   end
0038 end
0039 
0040 % Collect input ao's, plist's and ao variable names
0041 in_names = {};
0042 for ii = 1:nargin
0043   in_names{end+1} = inputname(ii);
0044 end
0045 
0046 [as, ps, invars] = collect_inputs(varargin, in_names);
0047 
0048 % check plist
0049 if isempty(ps)
0050   pl = getDefaultPL();
0051 else
0052   pl = combine(ps, getDefaultPL);
0053 end
0054 
0055 %% go through analysis objects
0056 for j=1:numel(as)
0057   a = as(j);
0058   d = get(a, 'data');
0059   dinfo = whos('d');
0060 
0061   % Which data type do we have
0062   dtype = dinfo.class;
0063   switch dtype
0064     case 'cdata'
0065       if size(d.y,1) ~= size(d.y,2)
0066         error('### The value (y) of data must be a square matrix.')
0067       else
0068         %disp('* INVERSE of cdata object');
0069 
0070         % make a new cdata object
0071         [h, c] = single_operation(d, 'inv', pl);
0072 
0073         % make output analysis object
0074         h = set(h, 'inhists', [a.hist]);
0075 
0076         %% Set the var_name to the history
0077         h = set(h, 'invars', cellstr(invars{j}));
0078 
0079         b = ao(c, h);
0080         b = setnh(b, 'name',  sprintf('inv(%s)', char(invars{j})));
0081       end
0082 
0083     case {'tsdata','fsdata','xydata'}
0084       error('### this function works for cdata type AO only')
0085     otherwise
0086       error('### unknown data type.')
0087 
0088   end
0089 
0090   % add to output
0091   bs = [bs b];
0092 end
0093 
0094 % Reshape the ouput to the same size of the input
0095 bs = reshape(bs, size(as));
0096 varargout{1} = bs;
0097 
0098 %% Get default params
0099 function plo = getDefaultPL()
0100 
0101 plo = plist();
0102 
0103 % END

Generated on Tue 22-Jan-2008 10:39:13 by m2html © 2003