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.html,v 1.1 2007/06/08 14:15:03 hewitson 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           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       % There are two cases:
0182       %   ao.data(1:12)
0183       %   ao(2).data
0184 
0185       switch index(1).type
0186         case '.'
0187 
0188           % INFO: ao1.data(1) or ao1.data(2:12)
0189           %       It does not matter what kind of value the data is
0190           %       data   = ao1.data(1:12)
0191           %       [t,x]  = ao1.data(1:12)
0192           %       [f,xx] = ao1.data(1:12)
0193           switch index(1).subs
0194             case 'data'
0195               % INFO: ao1.data.fs
0196               %       ao1.data(1:12)
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         % INFO: ao_vector(2).data;
0213         %       ao_vector(2).hist;
0214         %       ao_matrix(1,2).data;
0215         %       ao_matrix(2,1).hist;
0216         case '()'
0217 
0218           if length(index(1).subs{1}) == 1
0219 
0220             % INFO: ao_vector(2).data;
0221             %       ao_vector(2).hist;
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             % INFO: ao_matrix(1,2).data;
0236             %       ao_matrix(2,1).hist;
0237             elseif length(index(1).subs) == 2
0238               % Evaluate the matrix dimension. Exceeds the index the matrix
0239               % dimension throw an error.
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           % INFO: ao_all(1:2).data
0267           else
0268             error('### do not use more than one index.');
0269           end
0270 
0271       end
0272 
0273     case 3
0274       % INFO: ao1(1).data(1:12)
0275 
0276       error('programm code is not finished');
0277 
0278     otherwise
0279       error('### unknown indexing method for ao objects.');
0280   end
0281 end
0282 % END
0283

Generated on Fri 08-Jun-2007 16:09:11 by m2html © 2003