From e0027752d820010c073b379b0e48a16406a85edd Mon Sep 17 00:00:00 2001
From: Marco Ratto <marco.ratto@jrc.ec.europa.eu>
Date: Mon, 1 Oct 2012 08:50:47 +0200
Subject: [PATCH] Trap the case when second output of objective function is
 empty. (cherry picked from commit 560771bedc10089f306cc11b9fa9b8c33f43e751)

---
 matlab/mr_hessian.m | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/matlab/mr_hessian.m b/matlab/mr_hessian.m
index 0b059d9d6..9fe04ddad 100644
--- a/matlab/mr_hessian.m
+++ b/matlab/mr_hessian.m
@@ -133,7 +133,7 @@ while i<n
     end
     f1(:,i)=fx;
     if outer_product_gradient,
-        if any(isnan(ffx))
+        if any(isnan(ffx)) || isempty(ffx),
             ff1=ones(size(ff0)).*fx/length(ff0);
         else
             ff1=ffx;
@@ -143,7 +143,7 @@ while i<n
     [fx, ffx]=feval(func,xh1,DynareDataset,DynareOptions,Model,EstimatedParameters,BayesInfo,DynareResults);
     f_1(:,i)=fx;
     if outer_product_gradient,
-        if any(isnan(ffx))
+        if any(isnan(ffx)) || isempty(ffx),
             ff_1=ones(size(ff0)).*fx/length(ff0);
         else
             ff_1=ffx;
-- 
GitLab