Home > classes > @xydata > subsref.m

subsref

PURPOSE ^

SUBSREF Define field name indexing for xydata objects.

SYNOPSIS ^

function b = subsref(xy, index)

DESCRIPTION ^

 SUBSREF Define field name indexing for xydata objects.
 
 M Hewitson 31-01-07
 
 $Id: subsref.html,v 1.1 2007/06/08 14:15:09 hewitson Exp $

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function b = subsref(xy, index)
0002 
0003 % SUBSREF Define field name indexing for xydata objects.
0004 %
0005 % M Hewitson 31-01-07
0006 %
0007 % $Id: subsref.html,v 1.1 2007/06/08 14:15:09 hewitson Exp $
0008 %
0009 
0010 b = [];
0011 
0012 fieldName = '';
0013 switch length(index)
0014   case 1   % xy(1:10) or xy.x or xy.y
0015     switch index.type
0016       case '()'
0017         idx = index.subs{1};
0018         switch fieldName
0019           case ''
0020             b = [xy.x(idx) xy.y(idx)];
0021           case 'x'
0022             b = xy.x(idx);
0023           case 'y'
0024             b = xy.y(idx);
0025           otherwise
0026             error('### unknown field to index 1.');
0027         end
0028       case '.'
0029         fieldName = index.subs;
0030         eval(sprintf('b = xy.%s;', fieldName));        
0031       otherwise
0032         error('### unknown indexing method for xydata objects.');
0033     end
0034   case 2 % ts.t(1:10) or ts.x(1:10)
0035    
0036     if index(1).type == '.'
0037       % first index gets us field name
0038       fieldName = index(1).subs;
0039       % second index gets us indices
0040       idx = index(2).subs{1};
0041       switch fieldName
0042         case 'x'
0043           b = xy.x(idx);
0044         case 'y'
0045           b = xy.y(idx);
0046         otherwise
0047           error('### unknown field to index 1.');
0048         end
0049     else      
0050       error('### unknown indexing method for xydata objects.');
0051     end   
0052   otherwise
0053     error('### unknown indexing method for xydata objects.');
0054 end
0055 
0056 % END
0057

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