Skip to content
Snippets Groups Projects
Commit 50ee3686 authored by Stéphane Adjemian's avatar Stéphane Adjemian
Browse files

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))
parent 9559ed69
Branches
Tags
No related merge requests found
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment