Home > classes > @plist > subsref.m

subsref

PURPOSE ^

SUBSREF Define field name indexing for plist objects.

SYNOPSIS ^

function b = subsref(a, index)

DESCRIPTION ^

 SUBSREF Define field name indexing for plist objects.

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

 DESCRIPTION: SUBSREF Define field name indexing for tsdata objects.

 EXAMPLES:

  nesting level == 1

    >>   pl1     = pl_vector(2);
    >>             pl_vector(2);
    >>   pl1     = pl_matrix(2,1);    not possible
    >>   params  = pl.params;
    >>   version = pl.version;

  nesting level == 2

    >>        pl.params(2)
    >>        pl.params(2:12)
    >>   pl = pl.params(2);
    >>        pl.params(2,1)          not possible
    >>   pl = pl.params(2,1);         not possible
    >>        pl_vector(1).params
    >>   pl = pl_vector(1).params;
    >>        pl_vector(1:3).params;  not possible
    >>   pl = pl_vector(1:3).params;  not possible
    >>        pl_matrix(1,2).params
    >>   pl = pl_matrix(1,2).params;

 VERSION: $Id: subsref.html,v 1.2 2007/07/10 05:37:11 hewitson Exp $

 HISTORY: 31-01-07 M Hewitson
             Creation

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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function b = subsref(a, index)
0002 % SUBSREF Define field name indexing for plist objects.
0003 %
0004 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0005 %
0006 % DESCRIPTION: SUBSREF Define field name indexing for tsdata objects.
0007 %
0008 % EXAMPLES:
0009 %
0010 %  nesting level == 1
0011 %
0012 %    >>   pl1     = pl_vector(2);
0013 %    >>             pl_vector(2);
0014 %    >>   pl1     = pl_matrix(2,1);    not possible
0015 %    >>   params  = pl.params;
0016 %    >>   version = pl.version;
0017 %
0018 %  nesting level == 2
0019 %
0020 %    >>        pl.params(2)
0021 %    >>        pl.params(2:12)
0022 %    >>   pl = pl.params(2);
0023 %    >>        pl.params(2,1)          not possible
0024 %    >>   pl = pl.params(2,1);         not possible
0025 %    >>        pl_vector(1).params
0026 %    >>   pl = pl_vector(1).params;
0027 %    >>        pl_vector(1:3).params;  not possible
0028 %    >>   pl = pl_vector(1:3).params;  not possible
0029 %    >>        pl_matrix(1,2).params
0030 %    >>   pl = pl_matrix(1,2).params;
0031 %
0032 % VERSION: $Id: subsref.html,v 1.2 2007/07/10 05:37:11 hewitson Exp $
0033 %
0034 % HISTORY: 31-01-07 M Hewitson
0035 %             Creation
0036 %
0037 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0038 
0039 b = [];
0040 
0041 % index
0042 switch length(index)
0043   case 1
0044 
0045     % INFO: pl1 = pl_vector(2);
0046     switch index.type
0047       case '()'
0048         if length (index.subs) == 1
0049           idx = index.subs{1};
0050           b   = a(idx);
0051         else % length (index.subs) == 2
0052           error ('### Do not use a plist matrix.');
0053         end
0054 
0055       % INFO: params  = pl.params;
0056       %       version = pl.version;
0057       case '.'
0058 
0059         fieldName = index.subs;
0060 
0061         % Not possible field throw error
0062         if all(strcmp(fieldnames(a),fieldName)==0)
0063           error([sprintf('### %s is a non-existent field ',fieldName) ...
0064                          'of a parameter list object.']);
0065         end
0066 
0067         eval(sprintf('b = a.%s;', fieldName));
0068 
0069       otherwise
0070         error('### unknown indexing method for plist object.')
0071     end
0072 
0073   case 2
0074     % INFO:      pl.params(2)
0075     %            pl.params(2:12)
0076     %       pl = pl.params(2);
0077     %            pl.params(2,1)      not possible
0078     %       pl = pl.params(2,1);     not possible
0079     %            pl_vector(1).params
0080     %       pl = pl_vector(1).params;
0081     %            pl_vector(1:3).params;  not possible
0082     %       pl = pl_vector(1:3).params;  not possible
0083     %            pl_matrix(1,2).params
0084     %       pl = pl_matrix(1,2).params;
0085 
0086     if index(1).type == '.'
0087 
0088       fieldName = index(1).subs;
0089 
0090       if length(a) == 1
0091         eval(sprintf('b = subsref (a.%s, index(2));',fieldName))
0092       else
0093         error(['### output is not defined because the '...
0094                    'parameter list is vector or matrix.']);
0095       end
0096 
0097     % INFO:      pl_vector(1).params
0098     %       pl = pl_vector(1).params;
0099     %            pl_vector(1:3).params;  not possible
0100     %       pl = pl_vector(1:3).params;  not possible
0101 
0102     elseif strcmp (index(1).type, '()')
0103 
0104       if length(index(1).subs) == 1
0105         % INFO: pl = pl_vector(1).params;
0106         if length(index(1).subs{1}) == 1
0107           b = subsref (a(index(1).subs{1}), index(2));
0108         % INFO: pl = pl_vector(1:3).params;
0109         else
0110           error(['### output for the indexing '    ...
0111                  sprintf('(%d:%d) is not defined', min(index(1).subs{1}), ...
0112                                                    max(index(1).subs{1}))]);
0113         end
0114       % INFO:      pl_matrix(1,2).params
0115       %       pl = pl_matrix(1,2).params;
0116       elseif length(index(1).subs) == 2
0117         b = subsref (a(index(1).subs{1},index(1).subs{2}), index(2));
0118       end
0119 
0120     else
0121       error('### unknown indexing method for plist objects.');
0122     end
0123 
0124   otherwise % switch length(index)
0125     error('### unknown indexing method for plist object');
0126 end
0127 
0128 % END
0129

Generated on Wed 04-Jul-2007 19:03:10 by m2html © 2003