SUBSREF Define field name indexing for tsdata objects. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DESCRIPTION: SUBSREF Define field name indexing for tsdata objects. EXAMPLES: All possible accesses are possible. VERSION: $Id: subsref.m,v 1.12 2007/08/14 09:17:03 ingo Exp $ HISTORY: 31-01-07 M Hewitson Creation %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0001 function B = subsref(A, S) 0002 % SUBSREF Define field name indexing for tsdata objects. 0003 % 0004 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0005 % 0006 % DESCRIPTION: SUBSREF Define field name indexing for tsdata objects. 0007 % 0008 % EXAMPLES: All possible accesses are possible. 0009 % 0010 % VERSION: $Id: subsref.m,v 1.12 2007/08/14 09:17:03 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(tsd, index) 0019 % % SUBSREF Define field name indexing for tsdata objects. 0020 % % 0021 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0022 % % 0023 % % DESCRIPTION: SUBSREF Define field name indexing for tsdata objects. 0024 % % 0025 % % EXAMPLES: 0026 % % 0027 % % nesting level == 1 0028 % % 0029 % % >> data(2) 0030 % % >> data(2:12) 0031 % % >> [t,x] = data(2); 0032 % % >> [t,x] = data(2:12); 0033 % % >> x = data(2); not possible 0034 % % >> x = data(2:12); not possible 0035 % % >> data(2,1) not possible 0036 % % >> [t,x] = data(2,1); not possible 0037 % % >> x = data.x; 0038 % % >> t = data.t; 0039 % % >> name = data.name; 0040 % % ... 0041 % % 0042 % % nesting level == 2 0043 % % 0044 % % >> data.t(2) 0045 % % >> data.t(2:12) 0046 % % >> t = data.t(2); 0047 % % >> data.t(2,1) not possible 0048 % % >> t = data.t(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.12 2007/08/14 09:17:03 ingo Exp $ 0057 % % 0058 % % HISTORY: 31-01-07 M Hewitson 0059 % % Creation 0060 % % 0061 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0062 % 0063 % switch length(index) 0064 % case 1 % tsd(1:10) or tsd.t or tsd.x 0065 % switch index.type 0066 % 0067 % % INFO: data(2) 0068 % % data(2:12) 0069 % % [t,x] = data(2); 0070 % % [t,x] = data(2:12); 0071 % % x = data(2); not possible 0072 % % x = 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(tsd.t(idx)) 0081 % disp(tsd.x(idx)) 0082 % elseif nargout == 1 0083 % varargout{1} = [tsd.t(idx) tsd.x(idx)]; 0084 % elseif nargout == 2 0085 % varargout{1} = tsd.t(idx); 0086 % varargout{2} = tsd.x(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 % % [t,x] = 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: x = data.x; 0098 % % t = data.t; 0099 % % name = data.name; 0100 % % ... 0101 % case '.' 0102 % fieldName = index.subs; 0103 % eval(sprintf('varargout{1} = tsd.%s;', fieldName)); 0104 % 0105 % otherwise 0106 % error('### unknown indexing method for tsdata objects.'); 0107 % end 0108 % % INFO: 0109 % case 2 % tsd.t(1:10) or tsd.x(1:10) 0110 % 0111 % % INFO: data.t(2) 0112 % % data.t(2:12) 0113 % % t = data.t(2); 0114 % % data.t(2,1) not possible 0115 % % t = data.t(2,1); not possible 0116 % 0117 % if index(1).type == '.' 0118 % 0119 % fieldName = index(1).subs; 0120 % 0121 % % e.g. t = data.x(2,1); 0122 % if length(index(2).subs) > 1 && ~ischar(index(2).subs) 0123 % error('### the x- or y-data are a vector. Do not use two indices.'); 0124 % end 0125 % 0126 % switch fieldName 0127 % case 't' 0128 % t = tsd.t(index(2).subs{1}); 0129 % varargout{1} = t; 0130 % case 'x' 0131 % x = tsd.x(index(2).subs{1}); 0132 % varargout{1} = x; 0133 % case 't0' 0134 % varargout{1} = subsref(tsd.t0, index(2)); 0135 % otherwise 0136 % error('### not possible field. Use ''data.t'' or ''data.x''.'); 0137 % end 0138 % 0139 % % INFO: data_vector(1).t 0140 % % t = data_vector(1).t; 0141 % % data_vector(1:3).t; not possible 0142 % % t = data_vector(1:3).t; not possible 0143 % 0144 % elseif strcmp (index(1).type, '()') 0145 % 0146 % if length(index(1).subs) == 1 0147 % % INFO: t = data_vector(1).t; 0148 % if length(index(1).subs{1}) == 1 0149 % varargout{1} = subsref (tsd(index(1).subs{1}), index(2)); 0150 % % INFO: t = data_vector(1:3).t; 0151 % else 0152 % error(['### output for the indexing ' ... 0153 % sprintf('(%d:%d) is not defined', min(index(1).subs{1}), ... 0154 % max(index(1).subs{1}))]); 0155 % end 0156 % % INFO: data_matrix(1,2).t 0157 % % t = data_matrix(1,2).t; 0158 % elseif length(index(1).subs) == 2 0159 % varargout{1} = subsref (tsd(index(1).subs{1},index(1).subs{2}), index(2)); 0160 % end 0161 % 0162 % else 0163 % error('### unknown indexing method for tsdata objects.'); 0164 % end 0165 % otherwise 0166 % error('### unknown indexing method for tsdata objects.'); 0167 % end 0168 % 0169 % % END 0170 %