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.5 2007/07/18 13:58:44 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.5 2007/07/18 13:58:44 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 %% Check if this is a call for parameters
0026 if nargin == 2
0027   if isa(varargin{1}, 'ao') && ischar(varargin{2})
0028     in = char(varargin{2});
0029     if strcmp(in, 'Params')
0030       b = getDefaultPL();
0031       return
0032     end
0033   end
0034 end
0035 
0036 %% capture input variable names
0037 invars = {};
0038 for j=1:nargin
0039   invars = [invars cellstr(inputname(j))];
0040 end
0041 
0042 ALGONAME = mfilename;
0043 VERSION  = '$Id: index.m,v 1.5 2007/07/18 13:58:44 ingo Exp $';
0044 
0045 as = varargin{1};
0046 if ~isa(as, 'ao')
0047   error('### an array or matrix of AO objects is expected as first input argument.');
0048 end
0049 
0050 % Get indices
0051 pl = [];
0052 if nargin == 2
0053   if isa(varargin{2}, 'plist')
0054     pl = varargin{2};
0055     i  = find(pl, 'i');
0056     j  = find(pl, 'j');
0057     % Index the AO array
0058     if j == 0
0059       % Index the AO array
0060       asi = as(i);
0061     else
0062       % Index the AO array
0063       asi = as(i,j);
0064     end
0065   else
0066     i = varargin{2};
0067     j = 0;
0068     % Index the AO array
0069     asi = as(i);
0070   end
0071 elseif nargin == 3
0072   i = varargin{2};
0073   j = varargin{3};
0074   if j == 0
0075     % Index the AO array
0076     asi = as(i);
0077   else
0078     % Index the AO array
0079     asi = as(i,j);
0080   end
0081 else
0082   error('### incorrect inputs.');
0083 end
0084 
0085 
0086 si = size(asi);
0087 na = si(1)*si(2);
0088 if na ~= 1
0089   error('### I only support a single index currently.');
0090 end
0091 
0092 b = [];
0093 
0094 % Now build output AO
0095 if isempty(pl)
0096   pl = plist([param('i', i) param('j', j)]);
0097 end
0098 h = history(ALGONAME, VERSION, pl, get(asi,'hist'));
0099 h = set(h, 'invars', invars);
0100 
0101 % make output analysis object
0102 aout = ao(asi.data, h);
0103 
0104 % set name
0105 aout = set(aout, 'name', get(asi, 'name'));
0106 
0107 b = [b aout];
0108 
0109 %% Get default params
0110 function pl_default = getDefaultPL()
0111 
0112 disp('* creating default plist...');
0113   pl_default = plist();
0114   pl_default = append(pl_default, 'i', []);
0115   pl_default = append(pl_default, 'j', []);
0116 disp('* done.');
0117 
0118 
0119 % END

Generated on Mon 03-Sep-2007 12:12:34 by m2html © 2003