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.html,v 1.1 2007/06/08 14:15:03 hewitson 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 if nargout == 0
0167 eval(sprintf('varargout{1} = a.%s;', fieldName));
0168 elseif nargout == 1
0169 eval(sprintf('varargout{1} = a.%s;', fieldName));
0170 elseif nargout > 1
0171 for i=1:nargout
0172 eval(sprintf('varargout{%d} = a(%d).%s;', i, i, fieldName));
0173 end
0174 warning (sprintf('### the command ''out = %s.%s'' returns multiple outputs because ao is a vector or matrix.',...
0175 inputname(1), fieldName));
0176 end
0177 otherwise
0178 error('### unknown indexing method for fsdata objects.');
0179 end
0180 case 2
0181
0182
0183
0184
0185 switch index(1).type
0186 case '.'
0187
0188
0189
0190
0191
0192
0193 switch index(1).subs
0194 case 'data'
0195
0196
0197
0198 data_argout = subsref (a.data, index(2));
0199
0200 if nargout == 0
0201 disp (data_argout);
0202 elseif nargout == 1
0203 varargout{1} = data_argout;
0204 else
0205 varargout = num2cell(data_argout, 1);
0206 end
0207 otherwise
0208 error(sprintf ('### nothing to do with indexind %s object yet.',...
0209 index(1).subs));
0210 end
0211
0212
0213
0214
0215
0216 case '()'
0217
0218 if length(index(1).subs{1}) == 1
0219
0220
0221
0222 if length(index(1).subs) == 1
0223 switch index(2).subs
0224 case 'data'
0225 index = index(1).subs{1};
0226 varargout{1} = a(index).data;
0227 case 'hist'
0228 index = index(1).subs{1};
0229 varargout{1} = a(index).hist;
0230 otherwise
0231 error(sprintf ('### nothing to do with indexind %s object yet.',...
0232 index(2).subs));
0233 end
0234
0235
0236
0237 elseif length(index(1).subs) == 2
0238
0239
0240 [m,n] = size(a);
0241
0242 if (m >= index(1).subs{1})
0243 if (n >= index(1).subs{2})
0244
0245 switch index(2).subs
0246 case 'data'
0247 varargout{1} = a(index(1).subs{1}, index(1).subs{2}).data;
0248 case 'hist'
0249 varargout{1} = a(index(1).subs{1}, index(1).subs{2}).hist;
0250 otherwise
0251 error(sprintf ('### nothing to do with indexind %s object yet.',...
0252 index(2).subs));
0253 end
0254 else
0255 error('### the N index exceeds the MxN matrix dimension [%s].',...
0256 inputname(1));
0257 end
0258 else
0259 error('### the M index exceeds the MxN matrix dimension [%s].',...
0260 inputname(1));
0261 end
0262
0263 else
0264 error('Asdf')
0265 end
0266
0267 else
0268 error('### do not use more than one index.');
0269 end
0270
0271 end
0272
0273 case 3
0274
0275
0276 error('programm code is not finished');
0277
0278 otherwise
0279 error('### unknown indexing method for ao objects.');
0280 end
0281 end
0282
0283