


@info:
! @deftypefn {Function File} {@var{B} =} subsref (@var{A},@var{S})
! @anchor{@dynTime/subsref}
! @sp 1
! Overloads the subsref method for the Dynare time series class (@ref{dynTime}).
! @sp 2
! @strong{Inputs}
! @sp 1
! @table @ @var
! @item A
! Dynare time series object instantiated by @ref{dynSeries}.
! @item S
! Matlab's structure array S with two fields, type and subs. The type field is string containing '()', '@{@}', or '.', where '()' specifies
! integer subscripts, '@{@}' specifies cell array subscripts, and '.' specifies subscripted structure fields. The subs field is a cell array
! or a string containing the actual subscripts (see matlab's documentation).
! @end table
! @sp 1
! @strong{Outputs}
! @sp 1
! @table @ @var
! @item B
! Dynare time series object. Depending on the calling sequence @var{us} is a transformation of @var{ts} obtained by applying a public method on @var{ts},
! or a dynSeries object built by extracting a variable from @var{ts}, or a dynSeries object containing a subsample of the all the variable in @var{ts}.
! @end table
! @sp 2
! @strong{This function is called by:}
! @sp 2
! @strong{This function calls:}
! @sp 1
! @ref{dynTime}, @ref{@@dynTime/setFreq}, @ref{@@dynTime/setSize}, @ref{@@dynTime/setTime}
!
! @end deftypefn
@eod:

0001 function B = subsref(A, S) 0002 %@info: 0003 %! @deftypefn {Function File} {@var{B} =} subsref (@var{A},@var{S}) 0004 %! @anchor{@dynTime/subsref} 0005 %! @sp 1 0006 %! Overloads the subsref method for the Dynare time series class (@ref{dynTime}). 0007 %! @sp 2 0008 %! @strong{Inputs} 0009 %! @sp 1 0010 %! @table @ @var 0011 %! @item A 0012 %! Dynare time series object instantiated by @ref{dynSeries}. 0013 %! @item S 0014 %! Matlab's structure array S with two fields, type and subs. The type field is string containing '()', '@{@}', or '.', where '()' specifies 0015 %! integer subscripts, '@{@}' specifies cell array subscripts, and '.' specifies subscripted structure fields. The subs field is a cell array 0016 %! or a string containing the actual subscripts (see matlab's documentation). 0017 %! @end table 0018 %! @sp 1 0019 %! @strong{Outputs} 0020 %! @sp 1 0021 %! @table @ @var 0022 %! @item B 0023 %! Dynare time series object. Depending on the calling sequence @var{us} is a transformation of @var{ts} obtained by applying a public method on @var{ts}, 0024 %! or a dynSeries object built by extracting a variable from @var{ts}, or a dynSeries object containing a subsample of the all the variable in @var{ts}. 0025 %! @end table 0026 %! @sp 2 0027 %! @strong{This function is called by:} 0028 %! @sp 2 0029 %! @strong{This function calls:} 0030 %! @sp 1 0031 %! @ref{dynTime}, @ref{@@dynTime/setFreq}, @ref{@@dynTime/setSize}, @ref{@@dynTime/setTime} 0032 %! 0033 %! @end deftypefn 0034 %@eod: 0035 0036 if isequal(S(1).type,'.') 0037 switch S(1).subs 0038 case {'time','freq','init','last'} % Public members. 0039 B = builtin('subsref', A, S(1)); 0040 case {'setFreq','setSize','setTime'} % Give "dot access" to public methods. 0041 if length(S)==1 0042 B = feval(S(1).subs,A); 0043 else 0044 if isequal(S(2).type,'()') 0045 B = feval(S(1).subs,A,S(2).subs{:}); 0046 else 0047 error('dynTime::subsref: Something is wrong in your syntax!') 0048 end 0049 end 0050 otherwise 0051 error('dynTime::subsref: Unknown public method or member!') 0052 end 0053 elseif isequal(S.type,'()') % Extract a sub-sample. 0054 if length(S.subs)==1 0055 S.subs = [S.subs, ':']; 0056 end 0057 B = builtin('subsref', A.time, S); 0058 else 0059 error('dynTime::subsref: Something is wrong in your syntax!') 0060 end 0061 0062 %@test:1 0063 %$ addpath ../matlab 0064 %$ % Define a data set. 0065 %$ A = [transpose(1:10),2*transpose(1:10)]; 0066 %$ 0067 %$ % Define names 0068 %$ A_name = char('A1','A2'); 0069 %$ 0070 %$ % Instantiate a time series object. 0071 %$ ts1 = dynSeries(A,[],A_name,[]); 0072 %$ 0073 %$ % Call the tested method. 0074 %$ a = ts1(2:9); 0075 %$ 0076 %$ % Expected results. 0077 %$ e.data = [transpose(2:9),2*transpose(2:9)]; 0078 %$ e.nobs = 8;g 0079 %$ e.vobs = 2; 0080 %$ e.name = char('A1','A2'); 0081 %$ e.freq = 1; 0082 %$ tmp = ts1.time; e.time = tmp(2:9,:); 0083 %$ e.init = e.time(1,:); 0084 %$ e.last = e.time(end,:); 0085 %$ 0086 %$ % Check the results. 0087 %$ t(1) = dyn_assert(a.data,e.data); 0088 %$ t(2) = dyn_assert(a.time,e.time); 0089 %$ t(3) = dyn_assert(a.nobs,e.nobs); 0090 %$ t(4) = dyn_assert(a.vobs,e.vobs); 0091 %$ t(5) = dyn_assert(a.freq,e.freq); 0092 %$ t(6) = dyn_assert(a.init,e.init); 0093 %$ t(7) = dyn_assert(a.last,e.last); 0094 %$ T = all(t); 0095 %@eof:1 0096 0097 %@test:2 0098 %$ addpath ../matlab 0099 %$ % Define a data set. 0100 %$ A = [transpose(1:10),2*transpose(1:10)]; 0101 %$ 0102 %$ % Define names 0103 %$ A_name = char('A1','A2'); 0104 %$ 0105 %$ % Instantiate a time series object. 0106 %$ ts1 = dynSeries(A,[],A_name,[]); 0107 %$ 0108 %$ % Call the tested method. 0109 %$ a = ts1.A1; 0110 %$ 0111 %$ % Expected results. 0112 %$ e.data = transpose(1:10); 0113 %$ e.nobs = 10; 0114 %$ e.vobs = 1; 0115 %$ e.name = char('A1'); 0116 %$ e.freq = 1; 0117 %$ e.time = [transpose(1:10),ones(10,1)]; 0118 %$ e.init = e.time(1,:); 0119 %$ e.last = e.time(end,:); 0120 %$ 0121 %$ % Check the results. 0122 %$ t(1) = dyn_assert(a.data,e.data); 0123 %$ t(2) = dyn_assert(a.time,e.time); 0124 %$ t(3) = dyn_assert(a.nobs,e.nobs); 0125 %$ t(4) = dyn_assert(a.vobs,e.vobs); 0126 %$ t(5) = dyn_assert(a.freq,e.freq); 0127 %$ t(6) = dyn_assert(a.init,e.init); 0128 %$ t(7) = dyn_assert(a.last,e.last); 0129 %$ T = all(t); 0130 %@eof:2 0131 0132 %@test:3 0133 %$ addpath ../matlab 0134 %$ % Define a data set. 0135 %$ A = [transpose(1:10),2*transpose(1:10)]; 0136 %$ 0137 %$ % Define names 0138 %$ A_name = char('A1','A2'); 0139 %$ 0140 %$ % Instantiate a time series object. 0141 %$ ts1 = dynSeries(A,[],A_name,[]); 0142 %$ 0143 %$ % Call the tested method. 0144 %$ a = ts1.log; 0145 %$ 0146 %$ % Expected results. 0147 %$ e.data = log(A); 0148 %$ e.nobs = 10; 0149 %$ e.vobs = 2; 0150 %$ e.name = char('A1','A2'); 0151 %$ e.freq = 1; 0152 %$ tmp = ts1.time; e.time = tmp(1:10,:); 0153 %$ e.init = e.time(1,:); 0154 %$ e.last = e.time(end,:); 0155 %$ 0156 %$ % Check the results. 0157 %$ t(1) = dyn_assert(a.data,e.data); 0158 %$ t(2) = dyn_assert(a.time,e.time); 0159 %$ t(3) = dyn_assert(a.nobs,e.nobs); 0160 %$ t(4) = dyn_assert(a.vobs,e.vobs); 0161 %$ t(5) = dyn_assert(a.freq,e.freq); 0162 %$ t(6) = dyn_assert(a.init,e.init); 0163 %$ t(7) = dyn_assert(a.last,e.last); 0164 %$ T = all(t); 0165 %@eof:3