diff --git a/matlab/+occbin/IVF_posterior.m b/matlab/+occbin/IVF_posterior.m
index 533f5f6692f5b02e70e083426b4fbf66c347eb20..e3f8aca7217adec3fff11e16c990b89c9cc2e190 100644
--- a/matlab/+occbin/IVF_posterior.m
+++ b/matlab/+occbin/IVF_posterior.m
@@ -106,7 +106,14 @@ filtered_errs_init = zeros(sample_length,sum(err_index));
 if info(1)
     fval = Inf;
     exit_flag = 0;
+    atT=NaN(size(stateval(:,DynareResults.dr.order_var)'));
+    innov=NaN(Model.exo_nbr,sample_length);
     return
+else
+    atT = stateval(:,DynareResults.dr.order_var)';
+    innov = zeros(Model.exo_nbr,sample_length);
+    innov(diag(Model.Sigma_e)~=0,:)=filtered_errs';
+    updated_variables = atT*nan;
 end
 nobs=size(filtered_errs,1);
 
@@ -185,10 +192,7 @@ end
 % remember that the likelihood has already been multiplied by -1
 % hence, posterior is -1 times the log of the prior
 fval = like+prior;
-atT = stateval(:,DynareResults.dr.order_var)';
-innov = zeros(Model.exo_nbr,sample_length);
-innov(diag(Model.Sigma_e)~=0,:)=filtered_errs';
-updated_variables = atT*nan;
+
 BayesInfo.mf = BayesInfo.smoother_var_list(BayesInfo.smoother_mf);