From 50ee3686164b588e89c220c05a8a6e36c1b062f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Charybdis=29?= <stephane.adjemian@univ-lemans.fr> Date: Sun, 8 Jun 2014 15:20:46 +0200 Subject: [PATCH] Removed the possibility to extract subsamples from a dseries object with a vector of integers. If ts is a dates object with 100 observations (ts.nobs=100), the following syntax for selecting the last 90 observations *is not legal*: ts(11:end) ts has to be indexed instead with dates objects, as in the following example: ts(d1:d2) where d1 and d2 are dates objects. To select the 90 last observations, if the last date is unknown, the following syntax can be used: ts(ts.dates(11:end)) --- matlab/@dseries/subsref.m | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-) diff --git a/matlab/@dseries/subsref.m b/matlab/@dseries/subsref.m index ab3b08dc54..d30c2142d3 100644 --- a/matlab/@dseries/subsref.m +++ b/matlab/@dseries/subsref.m @@ -231,25 +231,7 @@ switch S(1).type B.init = A.init+(tdx(1)-1); B.dates = A.dates(tdx); elseif isvector(S(1).subs{1}) && all(isint(S(1).subs{1})) - % Extract a subsample using a vector of integers (observation index). - % Note that this does not work if S(1).subs is an integer scalar... In which case S(1).subs is interpreted as a lead/lag operator (as in the Dynare syntax). - % To extract one observation, a dates with one element input must be used. - if all(S(1).subs{1}>0) && all(S(1).subs{1}<=A.nobs) - if size(A.data,2)>1 - S(1).subs = [S(1).subs, ':']; - end - B = dseries(); - B.data = builtin('subsref', A.data, S(1)); - B.nobs = size(B.data,1); - B.vobs = A.vobs; - B.freq = A.freq; - B.dates = A.dates(S(1).subs{1}); - B.init = B.dates(1); - B.name = A.name; - B.tex = A.tex; - else - error('dseries::subsref: Indices are out of bounds!') - end + error('dseries::subsref: It is not possible to select observations with a vector of integers. You have to index with a dates object instead!'); else error('dseries::subsref: I have no idea of what you are trying to do!') end -- GitLab