Home > classes > @cdata > subsref.m

subsref

PURPOSE ^

SUBSREF Define field name indexing for cdata objects.

SYNOPSIS ^

function b = subsref(vals, index)

DESCRIPTION ^

 SUBSREF Define field name indexing for cdata objects.

 M Hewitson 31-01-07

 $Id: subsref.html,v 1.1 2007/06/08 14:15:05 hewitson Exp $

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function b = subsref(vals, index)
0002 
0003 % SUBSREF Define field name indexing for cdata objects.
0004 %
0005 % M Hewitson 31-01-07
0006 %
0007 % $Id: subsref.html,v 1.1 2007/06/08 14:15:05 hewitson Exp $
0008 %
0009 
0010 b = [];
0011 
0012 switch length(index)
0013   case 1   % vals(1:10) or vals(2,4) or vals.t or vals.x
0014     switch index.type
0015 
0016       case '()'
0017         if length(index.subs) == 1
0018           idx = index.subs{1};
0019           [m,n] = size(vals.vals);
0020 
0021           if (m*n >= index.subs{1})
0022             if (m ~= 1) && (n~=1)
0023               warning ('### you grab to a matrix with a single index', inputname(1));
0024             end
0025             b = [vals.vals(idx)];
0026           else
0027             error('### the index exceeds the vector dimension');
0028           end
0029 
0030         else %length(index.subs) == 2
0031           [m,n] = size(vals.vals);
0032             if (m >= index.subs{1})
0033               if (n >= index.subs{2})
0034                 b = vals.vals(index.subs{1}, index.subs{2});
0035               else
0036                 error('### the N index exceeds the MxN matrix dimension.');
0037               end
0038             else
0039               error('### the M index exceeds the MxN matrix dimension.');
0040             end
0041         end
0042 
0043       case '.'
0044         fieldName = index.subs;
0045         eval(sprintf('b = vals.%s;', fieldName));
0046 
0047       otherwise
0048         error('### unknown indexing method for tsdata objects.');
0049     end
0050   case 2 % vals.vals(1:10)
0051 
0052     if index(1).type == '.'
0053 
0054       % first index gets us field name
0055       fieldName = index(1).subs;
0056 
0057       % second index gets us indices
0058       idx = index(2).subs{1};
0059       switch fieldName
0060         case 'vals'
0061           b = subsref(vals, index(2));
0062         otherwise
0063           error('### unknown field to index 1.');
0064       end
0065 
0066     else
0067       error('### unknown indexing method for cdata objects.');
0068     end
0069   otherwise
0070     error('### unknown indexing method for cdata objects.');
0071 end
0072 
0073 % END
0074

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