diff --git a/doc/dynare.texi b/doc/dynare.texi
index 4e64d1c24548a5595ccb5606561b110a4c4676f7..16166a5aef149d6c4213808da3360e9ed050f09f 100644
--- a/doc/dynare.texi
+++ b/doc/dynare.texi
@@ -12826,7 +12826,7 @@ Baseline New Keynesian Model estimated in @cite{Fernández-Villaverde (2010)}. I
 
 Executes a user-defined function on parameter draws from the prior
 distribution. Dynare returns the results of the computations for all draws in an
-@math{ndraws} by @math{n} cell array named @var{oo_.prior_posterior_function_results}.
+@math{ndraws} by @math{n} cell array named @var{oo_.prior_function_results}.
 
 @optionshead
 
@@ -12850,7 +12850,8 @@ Number of draws used for sampling. Default: 500.
 
 @deffn Command posterior_function(@var{OPTIONS}) ;
 
-Same as the @ref{prior_function} command but for the posterior distribution.
+Same as the @ref{prior_function} command but for the posterior
+distribution. Results returned in @var{oo_.posterior_function_results}
 
 @optionshead
 
diff --git a/matlab/execute_prior_posterior_function.m b/matlab/execute_prior_posterior_function.m
index c1a4cd921ffd61bafdaacfdce344b283a581caf8..378d2237fb0e0112d2aa5d26bc4c39ae8f184f69 100644
--- a/matlab/execute_prior_posterior_function.m
+++ b/matlab/execute_prior_posterior_function.m
@@ -47,6 +47,7 @@ end
 %Create function handle
 functionhandle=str2func(posterior_function_name);
 
+prior = true;
 n_draws=options_.sampling_draws;
 % Get informations about the _posterior_draws files.
 if strcmpi(type,'posterior')
@@ -59,6 +60,7 @@ if strcmpi(type,'posterior')
         error('EXECUTE_POSTERIOR_FUNCTION: The draws could not be initialized')
     end
     n_draws=options_.sub_draws;
+    prior = false;
 elseif strcmpi(type,'prior')
     prior_draw(1);
 else
@@ -82,10 +84,16 @@ catch err
 end
 
 %initialize cell with number of columns
-oo_.prior_posterior_function_results=cell(n_draws,size(junk,2));
+results_cell=cell(n_draws,size(junk,2));
 
 %% compute function on draws
 for draw_iter = 1:n_draws
     M_ = set_all_parameters(parameter_mat(draw_iter,:),estim_params_,M_);
-    [oo_.prior_posterior_function_results(draw_iter,:)]=functionhandle(parameter_mat(draw_iter,:),M_,options_,oo_,estim_params_,bayestopt_,dataset_,dataset_info);
+    [results_cell(draw_iter,:)]=functionhandle(parameter_mat(draw_iter,:),M_,options_,oo_,estim_params_,bayestopt_,dataset_,dataset_info);
+end
+
+if prior
+    oo_.prior_function_results = results_cell;
+else
+    oo_.posterior_function_results = results_cell;
 end
diff --git a/tests/prior_posterior_function/fs2000_prior_posterior_function.mod b/tests/prior_posterior_function/fs2000_prior_posterior_function.mod
index a6d3998e0f0cf98fe0d63104214a2d841c032e7e..e10481dfd9c98421c2bef4956fec6a995c1f92f7 100644
--- a/tests/prior_posterior_function/fs2000_prior_posterior_function.mod
+++ b/tests/prior_posterior_function/fs2000_prior_posterior_function.mod
@@ -119,11 +119,11 @@ estimation(order=1,datafile='../fs2000/fsdat_simul', nobs=192, loglinear, mh_rep
 posterior_function(function='posterior_function_demo', sampling_draws=500);
 
 % read out the contents of the cell and put them into ndraws by ncolumns
-posterior_params=cell2mat(oo_.prior_posterior_function_results(:,1));
-posterior_steady_states=cell2mat(oo_.prior_posterior_function_results(:,2));
+posterior_params=cell2mat(oo_.posterior_function_results(:,1));
+posterior_steady_states=cell2mat(oo_.posterior_function_results(:,2));
 
 prior_function(function='posterior_function_demo');
 
 % read out the contents of the cell and put them into ndraws by ncolumns
-prior_params=cell2mat(oo_.prior_posterior_function_results(:,1));
-prior_steady_states=cell2mat(oo_.prior_posterior_function_results(:,2));
+prior_params=cell2mat(oo_.prior_function_results(:,1));
+prior_steady_states=cell2mat(oo_.prior_function_results(:,2));