diff --git a/matlab/+occbin/IVF_core.m b/matlab/+occbin/IVF_core.m
index a4c26fd0ad0a082f8e3e4651f84769fa5832649f..f3d4c4650798a14d2e9dcc542b158fec5f60401d 100644
--- a/matlab/+occbin/IVF_core.m
+++ b/matlab/+occbin/IVF_core.m
@@ -92,6 +92,9 @@ for this_period=1:sample_length
         filtered_errs=NaN;
         error_code(1) = 304;
         error_code(4) = 1000;
+        if this_period == 1
+            regime_history(this_period) = [];
+        end
         if options_.occbin.likelihood.waitbar; dyn_waitbar_close(hh_fig); end
         return
     end
diff --git a/matlab/+occbin/IVF_posterior.m b/matlab/+occbin/IVF_posterior.m
index 77329eb24ebc5503b91e147af8dc62bfcedc1fdf..dbfcaa9c8eac2c42f8f8f96918f59228017e1780 100644
--- a/matlab/+occbin/IVF_posterior.m
+++ b/matlab/+occbin/IVF_posterior.m
@@ -58,6 +58,8 @@ trend_coeff = [];
 obs = dataset_.data;
 obs_list = options_.varobs(:);
 exit_flag   = 1;
+% initialize output argument in case of early return
+regime_history = [];
 
 
 if size(xparam1,1)<size(xparam1,2)