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.9 2008/03/14 06:11:10 mauro Exp $ The following call returns a parameter list object that contains the default parameter values: >> pl = index(ao, 'Params') The following call returns a string that contains the routine CVS version: >> version = index(ao,'Version') The following call returns a string that contains the routine category: >> category = index(ao,'Category') HISTORY: 02-05-07 M Hewitson Creation %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
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.9 2008/03/14 06:11:10 mauro 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 % The following call returns a string that contains the routine CVS version: 0021 % 0022 % >> version = index(ao,'Version') 0023 % 0024 % The following call returns a string that contains the routine category: 0025 % 0026 % >> category = index(ao,'Category') 0027 % 0028 % HISTORY: 02-05-07 M Hewitson 0029 % Creation 0030 % 0031 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0032 0033 ALGONAME = mfilename; 0034 VERSION = '$Id: index.m,v 1.9 2008/03/14 06:11:10 mauro Exp $'; 0035 CATEGORY = 'Helper'; 0036 0037 %% Check if this is a call for parameters 0038 if nargin == 2 0039 if isa(varargin{1}, 'ao') && ischar(varargin{2}) 0040 in = char(varargin{2}); 0041 if strcmp(in, 'Params') 0042 b = getDefaultPL(); 0043 return 0044 elseif strcmp(in, 'Version') 0045 b = VERSION; 0046 return 0047 elseif strcmp(in, 'Category') 0048 b = CATEGORY; 0049 return 0050 end 0051 end 0052 end 0053 0054 %% capture input variable names 0055 invars = {}; 0056 for j=1:nargin 0057 invars = [invars cellstr(inputname(j))]; 0058 end 0059 0060 as = varargin{1}; 0061 if ~isa(as, 'ao') 0062 error('### an array or matrix of AO objects is expected as first input argument.'); 0063 end 0064 0065 % Get indices 0066 pl = []; 0067 if nargin == 2 0068 if isa(varargin{2}, 'plist') 0069 pl = varargin{2}; 0070 i = find(pl, 'i'); 0071 j = find(pl, 'j'); 0072 % Index the AO array 0073 if isempty(j) 0074 % Index the AO array 0075 asi = as(i); 0076 else 0077 % Index the AO array 0078 asi = as(i,j); 0079 end 0080 else 0081 i = varargin{2}; 0082 j = 0; 0083 % Index the AO array 0084 asi = as(i); 0085 end 0086 elseif nargin == 3 0087 i = varargin{2}; 0088 j = varargin{3}; 0089 if j == 0 0090 % Index the AO array 0091 asi = as(i); 0092 else 0093 % Index the AO array 0094 asi = as(i,j); 0095 end 0096 else 0097 error('### incorrect inputs.'); 0098 end 0099 0100 0101 si = size(asi); 0102 na = si(1)*si(2); 0103 if na ~= 1 0104 error('### I only support a single index currently.'); 0105 end 0106 0107 b = []; 0108 0109 % Now build output AO 0110 if isempty(pl) 0111 pl = plist([param('i', i) param('j', j)]); 0112 end 0113 h = history(ALGONAME, VERSION, pl, get(asi,'hist')); 0114 h = set(h, 'invars', invars); 0115 0116 % make output analysis object 0117 aout = setnh(asi, 'hist', h); 0118 0119 b = [b aout]; 0120 0121 %% Get default params 0122 function pl_default = getDefaultPL() 0123 0124 pl_default = plist(); 0125 pl_default = append(pl_default, 'i', []); 0126 pl_default = append(pl_default, 'j', []); 0127 0128 0129 % END