From 35df056905b230e96215c18f247d538ea9f83073 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= Date: Fri, 22 Jan 2021 18:15:08 +0100 Subject: [PATCH] =?UTF-8?q?histval=5Ffile:=20workaround=20for=20bug=20in?= =?UTF-8?q?=20MATLAB=20=E2=89=A4=20R2019a?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ref. dseries#45 --- matlab/histvalf.m | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/matlab/histvalf.m b/matlab/histvalf.m index a8f3092cd..cb2d1d496 100644 --- a/matlab/histvalf.m +++ b/matlab/histvalf.m @@ -13,7 +13,7 @@ function [endo_histval, exo_histval, exo_det_histval] = histvalf(M, options) % none -% Copyright (C) 2014-2020 Dynare Team +% Copyright (C) 2014-2021 Dynare Team % % This file is part of Dynare. % @@ -32,14 +32,31 @@ function [endo_histval, exo_histval, exo_det_histval] = histvalf(M, options) series = histvalf_initvalf('HISTVAL', M, options); k = M.orig_maximum_lag - M.maximum_lag + 1; -endo_histval = series{M.endo_names{:}}.data(k:end, :)'; -exo_histval = []; -if M.exo_nbr - exo_histval = series{M.exo_names{:}}.data(k:end, :)'; -end -exo_det_histval = []; -if M.exo_det_nbr - exo_det_histval = series{M.exo_names{:}}.data(k:end, :)'; -end +if ~isoctave && matlab_ver_less_than('9.7') + % Workaround for MATLAB bug described in dseries#45 + % The solution is to avoid using the "end" keyword + myend = nobs(series); + endo_histval = series{M.endo_names{:}}.data(k:myend, :)'; + + exo_histval = []; + if M.exo_nbr + exo_histval = series{M.exo_names{:}}.data(k:myend, :)'; + end + exo_det_histval = []; + if M.exo_det_nbr + exo_det_histval = series{M.exo_names{:}}.data(k:myend, :)'; + end +else + endo_histval = series{M.endo_names{:}}.data(k:end, :)'; + + exo_histval = []; + if M.exo_nbr + exo_histval = series{M.exo_names{:}}.data(k:end, :)'; + end + exo_det_histval = []; + if M.exo_det_nbr + exo_det_histval = series{M.exo_names{:}}.data(k:end, :)'; + end +end