diff --git a/matlab/@dseries/subsref.m b/matlab/@dseries/subsref.m index c2b45a36f..3b37e0a76 100644 --- a/matlab/@dseries/subsref.m +++ b/matlab/@dseries/subsref.m @@ -209,6 +209,13 @@ switch S(1).type else Dates = S(1).subs{1}; end + % Test if Dates is out of bounds + if min(Dates)max(A.dates) + error(['dseries::subsref: Indices are out of bounds! Subsample cannot end after ' date2string(A.dates(end)) '.']) + end % Extract a subsample using a dates object [junk,tdx] = intersect(A.dates.time,Dates.time,'rows'); B = dseries(); @@ -655,4 +662,40 @@ end %$ end %$ %$ T = all(t); -%@eof:15 \ No newline at end of file +%@eof:15 + +%@test:16 +%$ try +%$ ds = dseries(transpose(1:5)); +%$ ts = ds(2:6); +%$ t(1) = 0; +%$ catch +%$ t(1) = 1; +%$ end +%$ +%$ T = all(t); +%@eof:16 + +%@test:17 +%$ try +%$ ds = dseries(transpose(1:5)); +%$ ts = ds(dates('1Y'):dates('6Y')); +%$ t(1) = 0; +%$ catch +%$ t(1) = 1; +%$ end +%$ +%$ T = all(t); +%@eof:17 + +%@test:18 +%$ try +%$ ds = dseries(transpose(1:5)); +%$ ts = ds(dates('-2Y'):dates('4Y')); +%$ t(1) = 0; +%$ catch +%$ t(1) = 1; +%$ end +%$ +%$ T = all(t); +%@eof:18 \ No newline at end of file