Home > classes > @ao > index.m

index

PURPOSE ^

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

SYNOPSIS ^

function b = index(varargin)

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.
 
 usage: b = index(a, i)
        b = index(a, i, j)
 
 M Hewitson 02-05-07

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function b = index(varargin)
0002 
0003 % INDEX into an AO array or matrix. This properly captures the history.
0004 % This function is also called when standard () indexing is used for AO
0005 % arrays.
0006 %
0007 % usage: b = index(a, i)
0008 %        b = index(a, i, j)
0009 %
0010 % M Hewitson 02-05-07
0011 %
0012 
0013 % capture input variable names
0014 invars = {};
0015 for j=1:nargin
0016   invars = [invars cellstr(inputname(j))];
0017 end
0018 
0019 ALGONAME = mfilename;
0020 VERSION  = '$Id: index.html,v 1.1 2007/06/08 14:15:02 hewitson Exp $';
0021 
0022 as = varargin{1};
0023 if ~isa(as, 'ao')
0024   error('### an array or matrix of AO objects is expected as first input argument.');
0025 end
0026 
0027 % Get indices
0028 pl = [];
0029 if nargin == 2  
0030   if isa(varargin{2}, 'plist')
0031     pl = varargin{2};
0032     i  = find(pl, 'i');
0033     j  = find(pl, 'j');
0034     % Index the AO array
0035     if j == 0
0036       % Index the AO array
0037       asi = as(i);
0038     else
0039       % Index the AO array
0040       asi = as(i,j);
0041     end
0042   else
0043     i = varargin{2};
0044     j = 0;
0045     % Index the AO array
0046     asi = as(i);
0047   end
0048 elseif nargin == 3
0049   i = varargin{2};
0050   j = varargin{3};
0051   if j == 0
0052     % Index the AO array
0053     asi = as(i);
0054   else
0055     % Index the AO array
0056     asi = as(i,j);
0057   end
0058 else
0059   error('### incorrect inputs.');
0060 end
0061 
0062 
0063 si = size(asi);
0064 na = si(1)*si(2);
0065 if na ~= 1
0066   error('### I only support a single index currently.');
0067 end
0068 
0069 b = [];
0070 
0071 % Now build output AO
0072 if isempty(pl)
0073   pl = plist([param('i', i) param('j', j)]);
0074 end
0075 h = history(ALGONAME, VERSION, pl, get(asi,'hist'));
0076 h = set(h, 'invars', invars);
0077 
0078 % make output analysis object
0079 aout = ao(asi.data, h);
0080 
0081 % set name
0082 aout = set(aout, 'name', get(asi, 'name'));
0083 
0084 b = [b aout];
0085

Generated on Fri 08-Jun-2007 16:09:11 by m2html © 2003