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