diff --git a/matlab/execute_prior_posterior_function.m b/matlab/execute_prior_posterior_function.m
index 7e77a6ae8490fa4e6302d4ec03de0c6608b91aa3..1370ab34ee4176a34a3cbd20aa38770675e1fdd5 100644
--- a/matlab/execute_prior_posterior_function.m
+++ b/matlab/execute_prior_posterior_function.m
@@ -62,6 +62,13 @@ if strcmpi(type,'posterior')
     n_draws=options_.sub_draws;
     prior = false;
 elseif strcmpi(type,'prior')
+    if isempty(bayestopt_)
+        if ~isempty(estim_params_) && ~(isfield(estim_params_,'nvx') && (size(estim_params_.var_exo,1)+size(estim_params_.var_endo,1)+size(estim_params_.corrx,1)+size(estim_params_.corrn,1)+size(estim_params_.param_vals,1))==0)
+            [xparam1,estim_params_,bayestopt_,lb,ub,M_] = set_prior(estim_params_,M_,options_);
+        else
+            error('The prior distributions are not properly set up.')
+        end
+    end
     prior_draw(bayestopt_, options_.prior_trunc);
 else
     error('EXECUTE_POSTERIOR_FUNCTION: Unknown type!')