From 1f20ceb46168074e7400b206774282dd27a2f1fd Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Scylla=29?=
 <stephane.adjemian@univ-lemans.fr>
Date: Sun, 23 Jul 2017 23:21:36 +0200
Subject: [PATCH] Fixed bug in filtered variables with trend.

Was crashing in models with only one observed variable. The squeeze function
cannot be used in this case, only the first dimension  of
stock_filter_step_ahead should be squeezed.
---
 matlab/prior_posterior_statistics_core.m | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/matlab/prior_posterior_statistics_core.m b/matlab/prior_posterior_statistics_core.m
index 03cc43a3e0..8e39e5ae2c 100644
--- a/matlab/prior_posterior_statistics_core.m
+++ b/matlab/prior_posterior_statistics_core.m
@@ -260,23 +260,23 @@ for b=fpar:B
             else
                 constant_part=repmat(SteadyState(dr.order_var)',[length(options_.filter_step_ahead),1,gend+max(options_.filter_step_ahead)]);
             end
-
-            stock_filter_step_ahead(:,dr.order_var,:,irun(4)) = aK(options_.filter_step_ahead,1:endo_nbr,:) + ...
-                constant_part;
-
+            stock_filter_step_ahead(:,dr.order_var,:,irun(4)) = aK(options_.filter_step_ahead,1:endo_nbr,:) + constant_part;
             %now add trend to observables
             for ii=1:length(options_.filter_step_ahead)
                 if options_.prefilter
-                    stock_filter_step_ahead(ii,IdObs,:,irun(4)) = squeeze(stock_filter_step_ahead(ii,IdObs,:,irun(4)))...
-                        +repmat(mean_correction(:,1),1,gend+max(options_.filter_step_ahead))... %constant correction
+                    zdim = size(stock_filter_step_ahead(ii,IdObs,:,irun(4)));
+                    squeezed = reshape(stock_filter_step_ahead(ii,IdObs,:,irun(4)), [zdim(2:end) 1]);
+                    stock_filter_step_ahead(ii,IdObs,:,irun(4)) = squeezed ...
+                        +repmat(mean_correction(:,1),1,gend+max(options_.filter_step_ahead)) ... %constant correction
                         +[trend_addition repmat(trend_addition(:,end),1,max(options_.filter_step_ahead))+trend_coeff*[1:max(options_.filter_step_ahead)]]; %trend
                 else
-                    stock_filter_step_ahead(ii,IdObs,:,irun(4)) = squeeze(stock_filter_step_ahead(ii,IdObs,:,irun(4)))...
+                    zdim = size(stock_filter_step_ahead(ii,IdObs,:,irun(4)));
+                    squeezed = reshape(stock_filter_step_ahead(ii,IdObs,:,irun(4)), [zdim(2:end) 1]);
+                    stock_filter_step_ahead(ii,IdObs,:,irun(4)) = squeezed ...
                         +[trend_addition repmat(trend_addition(:,end),1,max(options_.filter_step_ahead))+trend_coeff*[1:max(options_.filter_step_ahead)]]; %trend
                 end
             end
         end
-
         if horizon
             yyyy = alphahat(iendo,i_last_obs);
             yf = forcst2a(yyyy,dr,zeros(horizon,exo_nbr));
-- 
GitLab