diff --git a/matlab/random_walk_metropolis_hastings_core.m b/matlab/random_walk_metropolis_hastings_core.m
index 128a7f99c980896c0304677b6d1c1d1534fd4f24..be1a9c8cccb1c81de2a264ea5a39da9071dc5922 100644
--- a/matlab/random_walk_metropolis_hastings_core.m
+++ b/matlab/random_walk_metropolis_hastings_core.m
@@ -26,6 +26,12 @@ global bayestopt_ estim_params_ options_  M_ oo_
 
 struct2local(myinputs);
 
+if whoiam,
+    % initialize persistent variables in priordens()
+priordens(xparam1,bayestopt_.pshape,bayestopt_.p6,bayestopt_.p7, ...
+          bayestopt_.p3,bayestopt_.p4,1);
+end
+
 
 MhDirectoryName = CheckPath('metropolis');