SUBSREF Define field name indexing for analysis objects. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DESCRIPTION: SUBSREF Define field name indexing for analysis objects. EXAMPLES: All possible accesses are possible. VERSION: $Id: subsref.m,v 1.13 2007/08/01 13:55:52 ingo Exp $ HISTORY: 31-01-07 M Hewitson Creation %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0001 function B = subsref(A, S) 0002 % SUBSREF Define field name indexing for analysis objects. 0003 % 0004 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0005 % 0006 % DESCRIPTION: SUBSREF Define field name indexing for analysis objects. 0007 % 0008 % EXAMPLES: All possible accesses are possible. 0009 % 0010 % VERSION: $Id: subsref.m,v 1.13 2007/08/01 13:55:52 ingo Exp $ 0011 % 0012 % HISTORY: 31-01-07 M Hewitson 0013 % Creation 0014 % 0015 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0016 B = builtin('subsref', A, S); 0017 0018 % function varargout = subsref(varargin) 0019 % % SUBSREF Define field name indexing for ao objects. 0020 % % 0021 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0022 % % 0023 % % DESCRIPTION: SUBSREF Define field name indexing for ao objects. 0024 % % 0025 % % EXAMPLES: 0026 % % 0027 % % nesting level == 1 0028 % % 0029 % % >> ao = ao_matrix(1,2); 0030 % % >> ao = ap_vector(2); 0031 % % >> ao = ao_vector(1:10); 0032 % % >> ao = ao_matrix(1,2); 0033 % % >> ao = ap_vector(2); 0034 % % >> ao = ao_vector(1:10); 0035 % % 0036 % % nesting level == 2 0037 % % 0038 % % >> data = ao.data(1:12) 0039 % % >> [t,x] = ao.data(1:12) 0040 % % >> [f,xx] = ao.data(1:12) 0041 % % >> fs = ao.data.fs 0042 % % >> data = ao_vector(2).data; 0043 % % >> hist = ao_vector(2).hist; 0044 % % >> data = ao_matrix(1,2).data; 0045 % % >> hist = ao_matrix(2,1).hist; 0046 % % 0047 % % HISTORY: 31-01-07 M Hewitson 0048 % % Creation 0049 % % 0050 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0051 % 0052 % ALGONAME = mfilename; 0053 % VERSION = '$Id: subsref.m,v 1.13 2007/08/01 13:55:52 ingo Exp $'; 0054 % 0055 % b = []; 0056 % fieldName = ''; 0057 % 0058 % % switch on history tracking for subsref 0059 % HISTORY_ON = 0; 0060 % 0061 % if isa(varargin{1}, 'ao') && isa(varargin{2}, 'plist') 0062 % 0063 % pl = varargin{2}; 0064 % i = find(pl, 'i'); 0065 % j = find(pl, 'j'); 0066 % if isempty(i) 0067 % error('### no i index found in plist'); 0068 % end 0069 % index.type = '()'; 0070 % index.subs{1} = i; 0071 % if ~isempty(j) 0072 % index.subs{2} = j; 0073 % end 0074 % varargout{1} = subsref(varargin{1}, index); 0075 % else 0076 % 0077 % a = varargin{1}; 0078 % index = varargin{2}; 0079 % 0080 % switch length(index) 0081 % % INFO: ao = ao_matrix(1,2); 0082 % % ao = ap_vector(2); 0083 % % ao = ao_vector(1:10); 0084 % case 1 0085 % 0086 % switch index.type 0087 % case '()' 0088 % % INFO: ao = ao_matrix(1,2); 0089 % if length(index.subs) == 2 0090 % 0091 % % Evaluate the matrix dimension. Exceeds the index the matrix 0092 % % dimension throw an error. 0093 % [m,n] = size(a); 0094 % 0095 % if (m >= index.subs{1}) 0096 % if (n >= index.subs{2}) 0097 % 0098 % ao_out = a(index.subs{1}, index.subs{2}); 0099 % if HISTORY_ON 0100 % pl = plist([param('i', index.subs{1}) ... 0101 % param('j', index.subs{2})]); 0102 % h = history('subsref', VERSION, pl, [a.hist]); 0103 % % INGO h = history('select', VERSION, pl, [a(index.subs{1},index.subs{2}).hist]); 0104 % vars_name = sprintf('%s(%d,%d)', ... 0105 % inputname(1), ... 0106 % index.subs{1},... 0107 % index.subs{2}); 0108 % h = set(h, 'invars', cellstr(vars_name)); 0109 % ao_out.hist = h; 0110 % end 0111 % varargout{1} = ao_out; 0112 % 0113 % else 0114 % error('### the N index exceeds the MxN matrix dimension [%s].',... 0115 % inputname(1)); 0116 % end 0117 % else 0118 % error('### the M index exceeds the MxN matrix dimension [%s].',... 0119 % inputname(1)); 0120 % end 0121 % 0122 % % INFO: ao = ao_vector(1); 0123 % % ao = ao_vector(1:3); 0124 % else % length (index.subs == 1) 0125 % 0126 % % Evaluate the matrix dimension. Exceeds the single index the n*m 0127 % % dimension throw an error. 0128 % [m,n] = size(a); 0129 % 0130 % if (m*n >= index.subs{1}) 0131 % 0132 % if (m ~= 1) && (n~=1) 0133 % warning ('### you grab to a matrix with a single index'); 0134 % end 0135 % 0136 % ao_out = a(index.subs{1}); 0137 % 0138 % % Add history for each element of the vector/matrix 0139 % % ao_vector(2) or ao_vector(1:2) 0140 % if HISTORY_ON 0141 % 0142 % 0143 % for i=1:length(ao_out) 0144 % 0145 % % ao_vector(2) 0146 % if length(ao_out) == 1 0147 % pl = plist(param('i', index.subs{1})); 0148 % % INGO h = history('select', VERSION, pl, [a(index.subs{1}).hist]); 0149 % h = history('subsref', VERSION, pl, [a.hist]); 0150 % 0151 % vars_name = sprintf('%s(%d)',inputname(1), index.subs{1}); 0152 % h = set(h, 'invars', cellstr(vars_name)); 0153 % else % ao_vector(1:3) 0154 % pl = plist([param('i', index.subs{1}(1)) ... 0155 % param('k', index.subs{1}(end))]); 0156 % % INGO h = history('subsref', VERSION, pl, [a(index.subs{1}).hist]); 0157 % h = history('subsref', VERSION, pl, [a.hist]); 0158 % 0159 % vars_name = sprintf('%s(%d:%d) --> %d', ... 0160 % inputname(1), ... 0161 % index.subs{1}(1), ... 0162 % index.subs{1}(end), ... 0163 % i); 0164 % h = set(h, 'invars', cellstr(vars_name)); 0165 % end 0166 % 0167 % ao_out(i) = set (ao_out(i), 'hist', h); 0168 % end 0169 % 0170 % end % HISTORY_ON 0171 % 0172 % varargout{1} = ao_out; 0173 % else 0174 % error('### the index exceeds the vector dimension [%s].',... 0175 % inputname(1)); 0176 % end 0177 % 0178 % end 0179 % 0180 % case '.' 0181 % fieldName = index.subs; 0182 % 0183 % % Not possible field? 0184 % if all(strcmp(fieldnames(a),fieldName)==0) 0185 % error([sprintf('### %s is a non-existent field ',fieldName) ... 0186 % 'of an analysis object.']); 0187 % end 0188 % 0189 % if nargout == 0 0190 % eval(sprintf('varargout{1} = a.%s;', fieldName)); 0191 % elseif nargout == 1 0192 % eval(sprintf('varargout{1} = a.%s;', fieldName)); 0193 % elseif nargout > 1 0194 % for i=1:nargout 0195 % eval(sprintf('varargout{%d} = a(%d).%s;', i, i, fieldName)); 0196 % end 0197 % warning ([sprintf('### the command ''out = %s.%s'' ', ... 0198 % inputname(1), fieldName) ... 0199 % 'returns multiple outputs because ' ... 0200 % 'ao is a vector or matrix.']); 0201 % end 0202 % otherwise 0203 % error('### unknown indexing method for analysis objects.'); 0204 % end 0205 % case 2 0206 % % There are two cases: 0207 % % ao.data(1:12) 0208 % % ao(2).data 0209 % 0210 % switch index(1).type 0211 % case '.' 0212 % 0213 % % INFO: ao1.data(1) or ao1.data(2:12) 0214 % % It does not matter what kind of value the data is 0215 % % data = ao1.data(1:12) 0216 % % [t,x] = ao1.data(1:12) 0217 % % [f,xx] = ao1.data(1:12) 0218 % switch index(1).subs 0219 % case 'data' 0220 % % INFO: ao1.data.fs 0221 % % ao1.data(1:12) 0222 % 0223 % data_argout = subsref (a.data, index(2)); 0224 % 0225 % if nargout == 0 0226 % disp (data_argout); 0227 % elseif nargout == 1 0228 % varargout{1} = data_argout; 0229 % else 0230 % varargout = num2cell(data_argout, 1); 0231 % end 0232 % otherwise 0233 % error('### nothing to do with indexind %s object yet.',index(1).subs); 0234 % end 0235 % 0236 % % INFO: ao_vector(2).data; 0237 % % ao_vector(2).hist; 0238 % % ao_matrix(1,2).data; 0239 % % ao_matrix(2,1).hist; 0240 % case '()' 0241 % 0242 % if length(index(1).subs{1}) == 1 0243 % 0244 % % INFO: ao_vector(2).data; 0245 % % ao_vector(2).hist; 0246 % if length(index(1).subs) == 1 0247 % switch index(2).subs 0248 % case 'data' 0249 % index = index(1).subs{1}; 0250 % varargout{1} = a(index).data; 0251 % case 'hist' 0252 % index = index(1).subs{1}; 0253 % varargout{1} = a(index).hist; 0254 % otherwise 0255 % error('### nothing to do with indexind %s object yet.',index(2).subs); 0256 % end 0257 % 0258 % % INFO: ao_matrix(1,2).data; 0259 % % ao_matrix(2,1).hist; 0260 % elseif length(index(1).subs) == 2 0261 % % Evaluate the matrix dimension. Exceeds the index the matrix 0262 % % dimension throw an error. 0263 % [m,n] = size(a); 0264 % 0265 % if (m >= index(1).subs{1}) 0266 % if (n >= index(1).subs{2}) 0267 % 0268 % switch index(2).subs 0269 % case 'data' 0270 % varargout{1} = a(index(1).subs{1}, index(1).subs{2}).data; 0271 % case 'hist' 0272 % varargout{1} = a(index(1).subs{1}, index(1).subs{2}).hist; 0273 % otherwise 0274 % error('### nothing to do with indexind %s object yet.',index(2).subs); 0275 % end 0276 % else 0277 % error('### the N index exceeds the MxN matrix dimension [%s].',... 0278 % inputname(1)); 0279 % end 0280 % else 0281 % error('### the M index exceeds the MxN matrix dimension [%s].',... 0282 % inputname(1)); 0283 % end 0284 % 0285 % else 0286 % error('### not possible error') 0287 % end 0288 % % INFO: ao_all(1:2).data 0289 % else 0290 % error('### do not use more than one index.'); 0291 % end 0292 % 0293 % end 0294 % 0295 % case 3 0296 % % INFO: ao_vector(2).data.x 0297 % % ao_vector(2:3).data.x not possible 0298 % % ao_matrix(2,1).data.x 0299 % % a.data(2).x not possible 0300 % % a.data(2:3).x not possible 0301 % % a.data(1,2).x not possible 0302 % % a.data.x(2) 0303 % % a.data.x(2:12) 0304 % % a.data.x(1,2) not possible 0305 % 0306 % 0307 % error('programm code is not finished'); 0308 % 0309 % otherwise 0310 % error('### unknown indexing method for ao objects.'); 0311 % end 0312 % end 0313 % % END 0314 %