Home > classes > @ao > index.m

index

PURPOSE ^

INDEX index into an AO array or matrix. This properly captures the history.

SYNOPSIS ^

function b = index(varargin)

DESCRIPTION ^

 INDEX index into an AO array or matrix. This properly captures the history.

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

 DESCRIPTION: INDEX into an AO array or matrix. This properly captures the
              history. This function is also called when standard () indexing
              is used for AO arrays.

 CALL:        b = index(a, i)
              b = index(a, i, j)

 VERSION:     $Id: index.m,v 1.6 2007/11/02 12:26:24 ingo Exp $

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

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

 HISTORY: 02-05-07 M Hewitson
             Creation

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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function b = index(varargin)
0002 % INDEX index into an AO array or matrix. This properly captures the history.
0003 %
0004 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0005 %
0006 % DESCRIPTION: INDEX into an AO array or matrix. This properly captures the
0007 %              history. This function is also called when standard () indexing
0008 %              is used for AO arrays.
0009 %
0010 % CALL:        b = index(a, i)
0011 %              b = index(a, i, j)
0012 %
0013 % VERSION:     $Id: index.m,v 1.6 2007/11/02 12:26:24 ingo Exp $
0014 %
0015 % The following call returns a parameter list object that contains the
0016 % default parameter values:
0017 %
0018 % >> pl = index(ao, 'Params')
0019 %
0020 % HISTORY: 02-05-07 M Hewitson
0021 %             Creation
0022 %
0023 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0024 
0025 ALGONAME = mfilename;
0026 VERSION  = '$Id: index.m,v 1.6 2007/11/02 12:26:24 ingo Exp $';
0027 
0028 %% Check if this is a call for parameters
0029 if nargin == 2
0030   if isa(varargin{1}, 'ao') && ischar(varargin{2})
0031     in = char(varargin{2});
0032     if strcmp(in, 'Params')
0033       b = getDefaultPL();
0034       return
0035     elseif strcmp(in, 'Version')
0036       b = VERSION;
0037       return
0038     end
0039   end
0040 end
0041 
0042 %% capture input variable names
0043 invars = {};
0044 for j=1:nargin
0045   invars = [invars cellstr(inputname(j))];
0046 end
0047 
0048 as = varargin{1};
0049 if ~isa(as, 'ao')
0050   error('### an array or matrix of AO objects is expected as first input argument.');
0051 end
0052 
0053 % Get indices
0054 pl = [];
0055 if nargin == 2
0056   if isa(varargin{2}, 'plist')
0057     pl = varargin{2};
0058     i  = find(pl, 'i');
0059     j  = find(pl, 'j');
0060     % Index the AO array
0061     if isempty(j)
0062       % Index the AO array
0063       asi = as(i);
0064     else
0065       % Index the AO array
0066       asi = as(i,j);
0067     end
0068   else
0069     i = varargin{2};
0070     j = 0;
0071     % Index the AO array
0072     asi = as(i);
0073   end
0074 elseif nargin == 3
0075   i = varargin{2};
0076   j = varargin{3};
0077   if j == 0
0078     % Index the AO array
0079     asi = as(i);
0080   else
0081     % Index the AO array
0082     asi = as(i,j);
0083   end
0084 else
0085   error('### incorrect inputs.');
0086 end
0087 
0088 
0089 si = size(asi);
0090 na = si(1)*si(2);
0091 if na ~= 1
0092   error('### I only support a single index currently.');
0093 end
0094 
0095 b = [];
0096 
0097 % Now build output AO
0098 if isempty(pl)
0099   pl = plist([param('i', i) param('j', j)]);
0100 end
0101 h = history(ALGONAME, VERSION, pl, get(asi,'hist'));
0102 h = set(h, 'invars', invars);
0103 
0104 % make output analysis object
0105 aout = setnh(asi, 'hist', h);
0106 
0107 b = [b aout];
0108 
0109 %% Get default params
0110 function pl_default = getDefaultPL()
0111 
0112   pl_default = plist();
0113   pl_default = append(pl_default, 'i', []);
0114   pl_default = append(pl_default, 'j', []);
0115 
0116 
0117 % END

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