From 1853d20daf7582a62f7f028148897ef9ed167166 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Thu, 18 Jul 2013 14:27:09 -0400 Subject: [PATCH] dynSeries: add scalar subtraction --- matlab/@dynSeries/minus.m | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/matlab/@dynSeries/minus.m b/matlab/@dynSeries/minus.m index 3154a9f32..ccd44f92e 100644 --- a/matlab/@dynSeries/minus.m +++ b/matlab/@dynSeries/minus.m @@ -40,6 +40,36 @@ function A = minus(B,C) % You should have received a copy of the GNU General Public License % along with Dynare. If not, see . +if isscalar(B) + assert(isa(C, 'dynSeries')); + b(1:size(C)) = B; + BB = dynSeries(b, C.time(1)); + BB.freq = C.freq; + BB.time = C.time; + BB.nobs = C.nobs; + BB.vobs = C.vobs; + BB.name = cell(BB.vobs,1); + BB.tex = cell(BB.vobs,1); + BB.name(1) = {num2str(B)}; + A = BB - C; + return; +end + +if isscalar(C) + assert(isa(B, 'dynSeries')); + c(1:size(C)) = C; + CC = dynSeries(C, B.time(1)); + CC.freq = B.freq; + CC.time = B.time; + CC.nobs = B.nobs; + CC.vobs = B.vobs; + CC.name = cell(CC.vobs,1); + CC.tex = cell(CC.vobs,1); + CC.name(1) = {num2str(C)}; + A = B - CC; + return; +end + if ~isequal(B.vobs,C.vobs) && ~(isequal(B.vobs,1) || isequal(C.vobs,1)) error(['dynSeries::minus: Cannot substract ' inputname(1) ' and ' inputname(2) ' (wrong number of variables)!']) else