SUBSREF Define field name indexing for cdata objects. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DESCRIPTION: SUBSREF Define field name indexing for cdata objects. EXAMPLES: All possible accesses are possible. VERSION: $Id: subsref.m,v 1.5 2007/08/01 13:55:52 ingo Exp $ HISTORY: 31-01-07 M Hewitson Creation %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0001 function B = subsref(A, S) 0002 % SUBSREF Define field name indexing for cdata objects. 0003 % 0004 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0005 % 0006 % DESCRIPTION: SUBSREF Define field name indexing for cdata objects. 0007 % 0008 % EXAMPLES: All possible accesses are possible. 0009 % 0010 % VERSION: $Id: subsref.m,v 1.5 2007/08/01 13:55:52 ingo Exp $ 0011 % 0012 % HISTORY: 31-01-07 M Hewitson 0013 % Creation 0014 % 0015 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0016 B = builtin('subsref', A, S); 0017 0018 % function b = subsref(vals, index) 0019 % % SUBSREF Define field name indexing for cdata objects. 0020 % % 0021 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0022 % % 0023 % % DESCRIPTION: SUBSREF Define field name indexing for cdata objects. 0024 % % 0025 % % EXAMPLES: 0026 % % 0027 % % nesting level == 1 0028 % % 0029 % % >> vals(2) 0030 % % >> vals = vals(2); 0031 % % >> 0032 % % >> vals = vals(2:12) 0033 % % >> vals(2,3) 0034 % % >> vals = vals(2,3); 0035 % % >> name = vals.name; 0036 % % >> ... 0037 % % 0038 % % nesting level == 2 0039 % % 0040 % % >> vals = vals.vals(2) 0041 % % vals.vals(2) 0042 % % >> vals = vals.vals(1:10) 0043 % % vals.vals(1:10) 0044 % % >> vals = vals.vals(1,3) 0045 % % vals.vals(1,3) 0046 % % vals_vector(1).vals not possible 0047 % % vals_vector(1:3).vals not possible 0048 % % vals_matrix(1:3).vals not possible 0049 % % 0050 % % VERSION: $Id: subsref.m,v 1.5 2007/08/01 13:55:52 ingo Exp $ 0051 % % 0052 % % HISTORY: 31-01-07 M Hewitson 0053 % % Creation 0054 % % 0055 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0056 % 0057 % b = []; 0058 % 0059 % switch length(index) 0060 % % vals(2) 0061 % % vals = vals(2); 0062 % % vals(2:12) 0063 % % vals = vals(2:12) 0064 % % vals(2,3) 0065 % % vals = vals(2,3); 0066 % % name = vals.name; 0067 % % ... 0068 % case 1 0069 % switch index.type 0070 % 0071 % case '()' 0072 % if length(index.subs) == 1 0073 % idx = index.subs{1}; 0074 % [m,n] = size(vals.vals); 0075 % 0076 % if (m*n >= index.subs{1}) 0077 % if (m ~= 1) && (n~=1) 0078 % warning (['### you grab to a matrix with a single index ', inputname(1)]); 0079 % end 0080 % b = [vals.vals(idx)]; 0081 % else 0082 % error('### the index exceeds the vector dimension'); 0083 % end 0084 % 0085 % else %length(index.subs) == 2 0086 % [m,n] = size(vals.vals); 0087 % if (m >= index.subs{1}) 0088 % if (n >= index.subs{2}) 0089 % b = vals.vals(index.subs{1}, index.subs{2}); 0090 % else 0091 % error('### the N index exceeds the MxN matrix dimension.'); 0092 % end 0093 % else 0094 % error('### the M index exceeds the MxN matrix dimension.'); 0095 % end 0096 % end 0097 % 0098 % case '.' 0099 % fieldName = index.subs; 0100 % eval(sprintf('b = vals.%s;', fieldName)); 0101 % 0102 % otherwise 0103 % error('### unknown indexing method for cdata objects.'); 0104 % end 0105 % 0106 % % vals = vals.vals(1) 0107 % % vals.vals(1) 0108 % % vals = vals.vals(1:10) 0109 % % vals.vals(1:10) 0110 % % vals = vals.vals(1,3) 0111 % % vals.vals(1,3) 0112 % case 2 0113 % 0114 % if index(1).type == '.' 0115 % 0116 % % first index gets us field name 0117 % fieldName = index(1).subs; 0118 % 0119 % switch fieldName 0120 % case 'vals' 0121 % b = subsref(vals, index(2)); 0122 % otherwise 0123 % error('### unknown field to index 1.'); 0124 % end 0125 % 0126 % else 0127 % error('### unknown indexing method for cdata objects.'); 0128 % end 0129 % otherwise 0130 % error('### unknown indexing method for cdata objects.'); 0131 % end 0132 % 0133 % % END 0134 %