SUBSREF Define field name indexing for xydata objects. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DESCRIPTION: SUBSREF Define field name indexing for xydata 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 xydata objects. 0003 % 0004 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0005 % 0006 % DESCRIPTION: SUBSREF Define field name indexing for xydata 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 varargout = subsref(xy, index) 0019 % % SUBSREF Define field name indexing for xydata objects. 0020 % % 0021 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0022 % % 0023 % % DESCRIPTION: SUBSREF Define field name indexing for xydata objects. 0024 % % 0025 % % EXAMPLES: 0026 % % 0027 % % nesting level == 1 0028 % % 0029 % % >> data(2) 0030 % % >> data(2:12) 0031 % % >> [x,y] = data(2); 0032 % % >> [x,y] = data(2:12); 0033 % % >> y = data(2); not possible 0034 % % >> y = data(2:12); not possible 0035 % % >> data(2,1) not possible 0036 % % >> [x,y] = data(2,1); not possible 0037 % % >> y = data.y; 0038 % % >> x = data.x; 0039 % % >> name = data.name; 0040 % % ... 0041 % % 0042 % % nesting level == 2 0043 % % 0044 % % >> data.x(2) 0045 % % >> data.x(2:12) 0046 % % >> x = data.x(2); 0047 % % >> data.x(2,1) not possible 0048 % % >> x = data.x(2,1); not possible 0049 % % >> data_vector(1).t 0050 % % >> t = data_vector(1).t; 0051 % % >> data_vector(1:3).t; not possible 0052 % % >> t = data_vector(1:3).t; not possible 0053 % % >> data_matrix(1,2).t 0054 % % >> t = data_matrix(1,2).t; 0055 % % 0056 % % VERSION: $Id: subsref.m,v 1.5 2007/08/01 13:55:52 ingo Exp $ 0057 % % 0058 % % HISTORY: 31-01-07 M Hewitson 0059 % % Creation 0060 % % 0061 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0062 % 0063 % switch length(index) 0064 % case 1 % xy(1:10) or xy.x or xy.y 0065 % switch index.type 0066 % 0067 % % INFO: data(2) 0068 % % data(2:12) 0069 % % [x,y] = data(2); 0070 % % [x,y] = data(2:12); 0071 % % y = data(2); not possible 0072 % % y = data(2:12); not possible 0073 % case '()' 0074 % if length (index.subs) == 1 0075 % 0076 % idx = index.subs{1}; 0077 % 0078 % % assure that the number of outputs matches 0079 % if nargout == 0 0080 % disp(xy.x(idx)) 0081 % disp(xy.y(idx)) 0082 % elseif nargout == 1 0083 % varargout{1} = [xy.x(idx) xy.y(idx)]; 0084 % elseif nargout == 2 0085 % varargout{1} = xy.x(idx); 0086 % varargout{2} = xy.y(idx); 0087 % else 0088 % error('### the number of outputs does not match. Please use two outputs.') 0089 % end 0090 % 0091 % % INFO: data(2,1) not possible 0092 % % [x,y] = data(2,1); not possible 0093 % else % length (index.subs) == 2 0094 % error ('### the x- or y-data are a vector. Do not use two indices.'); 0095 % end 0096 % 0097 % % INFO: y = data.y; 0098 % % x = data.x; 0099 % % name = data.name; 0100 % % ... 0101 % case '.' 0102 % fieldName = index.subs; 0103 % eval(sprintf('varargout{1} = xy.%s;', fieldName)); 0104 % 0105 % otherwise 0106 % error('### unknown indexing method for xydata objects.'); 0107 % end 0108 % % INFO: 0109 % case 2 % xy.x(1:10) or xy.y(1:10) 0110 % 0111 % % INFO: data.x(2) 0112 % % data.x(2:12) 0113 % % x = data.x(2); 0114 % % data.x(2,1) not possible 0115 % % x = data.x(2,1); not possible 0116 % % data_vector(1).x 0117 % % x = data_vector(1).x; 0118 % % data_vector(1:3).x; not possible 0119 % % x = data_vector(1:3).x; not possible 0120 % % data_matrix(1,2).x 0121 % % x = data_matrix(1,2).x; 0122 % 0123 % if index(1).type == '.' 0124 % 0125 % fieldName = index(1).subs; 0126 % 0127 % % e.g. t = data.x(2,1); 0128 % if length(index(2).subs) > 1 && ~ischar(index(2).subs) 0129 % error('### the x- or y-data are a vector. Do not use two indices.'); 0130 % end 0131 % 0132 % switch fieldName 0133 % case 'x' 0134 % x = xy.x(index(2).subs{1}); 0135 % varargout{1} = x; 0136 % case 'y' 0137 % y = xy.y(index(2).subs{1}); 0138 % varargout{1} = y; 0139 % otherwise 0140 % error('### not possible field. Use ''data.x'' or ''data.y''.'); 0141 % end 0142 % 0143 % % INFO: data_vector(1).x 0144 % % x = data_vector(1).x; 0145 % % data_vector(1:3).x; not possible 0146 % % x = data_vector(1:3).x; not possible 0147 % 0148 % elseif strcmp (index(1).type, '()') 0149 % 0150 % if length(index(1).subs) == 1 0151 % % INFO: x = data_vector(1).x; 0152 % if length(index(1).subs{1}) == 1 0153 % varargout{1} = subsref (xy(index(1).subs{1}), index(2)); 0154 % % INFO: x = data_vector(1:3).x; 0155 % else 0156 % error(['### output for the indexing ' ... 0157 % sprintf('(%d:%d) is not defined', min(index(1).subs{1}), ... 0158 % max(index(1).subs{1}))]); 0159 % end 0160 % % INFO: data_matrix(1,2).x 0161 % % x = data_matrix(1,2).x; 0162 % elseif length(index(1).subs) == 2 0163 % varargout{1} = subsref (xy(index(1).subs{1},index(1).subs{2}), index(2)); 0164 % end 0165 % 0166 % else 0167 % error('### unknown indexing method for xydata objects.'); 0168 % end 0169 % otherwise 0170 % error('### unknown indexing method for xydata objects.'); 0171 % end 0172 % 0173 % % END 0174 %