Home > classes > @ao > subsref.m

subsref

PURPOSE ^

SUBSREF Define field name indexing for ao objects.

SYNOPSIS ^

function varargout = subsref(varargin)

DESCRIPTION ^

 SUBSREF Define field name indexing for ao objects.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

 DESCRIPTION: SUBSREF Define field name indexing for ao objects.

 EXAMPLES:

  nesting level == 1

    >> ao = ao_matrix(1,2);
    >> ao = ap_vector(2);
    >> ao = ao_vector(1:10);
    >> ao = ao_matrix(1,2);
    >> ao = ap_vector(2);
    >> ao = ao_vector(1:10);

  nesting level == 2

    >> data   = ao.data(1:12)
    >> [t,x]  = ao.data(1:12)
    >> [f,xx] = ao.data(1:12)
    >> fs     = ao.data.fs
    >> data   = ao_vector(2).data;
    >> hist   = ao_vector(2).hist;
    >> data   = ao_matrix(1,2).data;
    >> hist   = ao_matrix(2,1).hist;

 HISTORY: 31-01-07 M Hewitson
             Creation

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function varargout = subsref(varargin)
0002 % SUBSREF Define field name indexing for ao objects.
0003 %
0004 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0005 %
0006 % DESCRIPTION: SUBSREF Define field name indexing for ao objects.
0007 %
0008 % EXAMPLES:
0009 %
0010 %  nesting level == 1
0011 %
0012 %    >> ao = ao_matrix(1,2);
0013 %    >> ao = ap_vector(2);
0014 %    >> ao = ao_vector(1:10);
0015 %    >> ao = ao_matrix(1,2);
0016 %    >> ao = ap_vector(2);
0017 %    >> ao = ao_vector(1:10);
0018 %
0019 %  nesting level == 2
0020 %
0021 %    >> data   = ao.data(1:12)
0022 %    >> [t,x]  = ao.data(1:12)
0023 %    >> [f,xx] = ao.data(1:12)
0024 %    >> fs     = ao.data.fs
0025 %    >> data   = ao_vector(2).data;
0026 %    >> hist   = ao_vector(2).hist;
0027 %    >> data   = ao_matrix(1,2).data;
0028 %    >> hist   = ao_matrix(2,1).hist;
0029 %
0030 % HISTORY: 31-01-07 M Hewitson
0031 %             Creation
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 % switch on history tracking for subsref
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     % INFO: ao = ao_matrix(1,2);
0065     %       ao = ap_vector(2);
0066     %       ao = ao_vector(1:10);
0067     case 1
0068 
0069       switch index.type
0070         case '()'
0071           % INFO: ao = ao_matrix(1,2);
0072           if length(index.subs) == 2
0073 
0074             % Evaluate the matrix dimension. Exceeds the index the matrix
0075             % dimension throw an error.
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 % INGO              h = history('select', VERSION, pl, [a(index.subs{1},index.subs{2}).hist]);
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           % INFO: ao = ao_vector(1);
0106           %       ao = ao_vector(1:3);
0107           else % length (index.subs == 1)
0108 
0109             % Evaluate the matrix dimension. Exceeds the single index the n*m
0110             % dimension throw an error.
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               % Add history for each element of the vector/matrix
0122               % ao_vector(2) or ao_vector(1:2)
0123               if HISTORY_ON
0124 
0125 
0126                 for i=1:length(ao_out)
0127 
0128                   % ao_vector(2)
0129                   if length(ao_out) == 1
0130                     pl = plist(param('i', index.subs{1}));
0131 % INGO                h = history('select', VERSION, pl, [a(index.subs{1}).hist]);
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 % ao_vector(1:3)
0137                     pl = plist([param('i', index.subs{1}(1)) ...
0138                                 param('k', index.subs{1}(end))]);
0139 % INGO                h = history('subsref', VERSION, pl, [a(index.subs{1}).hist]);
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 % HISTORY_ON
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           % Not possible field?
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       % There are two cases:
0190       %   ao.data(1:12)
0191       %   ao(2).data
0192 
0193       switch index(1).type
0194         case '.'
0195 
0196           % INFO: ao1.data(1) or ao1.data(2:12)
0197           %       It does not matter what kind of value the data is
0198           %       data   = ao1.data(1:12)
0199           %       [t,x]  = ao1.data(1:12)
0200           %       [f,xx] = ao1.data(1:12)
0201           switch index(1).subs
0202             case 'data'
0203               % INFO: ao1.data.fs
0204               %       ao1.data(1:12)
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         % INFO: ao_vector(2).data;
0221         %       ao_vector(2).hist;
0222         %       ao_matrix(1,2).data;
0223         %       ao_matrix(2,1).hist;
0224         case '()'
0225 
0226           if length(index(1).subs{1}) == 1
0227 
0228             % INFO: ao_vector(2).data;
0229             %       ao_vector(2).hist;
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             % INFO: ao_matrix(1,2).data;
0244             %       ao_matrix(2,1).hist;
0245             elseif length(index(1).subs) == 2
0246               % Evaluate the matrix dimension. Exceeds the index the matrix
0247               % dimension throw an error.
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           % INFO: ao_all(1:2).data
0275           else
0276             error('### do not use more than one index.');
0277           end
0278 
0279       end
0280 
0281     case 3
0282       % INFO: ao_vector(2).data.x
0283       %       ao_vector(2:3).data.x      not possible
0284       %       ao_matrix(2,1).data.x
0285       %       a.data(2).x                not possible
0286       %       a.data(2:3).x              not possible
0287       %       a.data(1,2).x              not possible
0288       %       a.data.x(2)
0289       %       a.data.x(2:12)
0290       %       a.data.x(1,2)              not possible
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 % END
0300

Generated on Mon 02-Jul-2007 12:19:41 by m2html © 2003