diff --git a/matlab/PlotPosteriorDistributions.m b/matlab/PlotPosteriorDistributions.m
index d96d6178cacecbe45bbc66c7b369e688bbdeba07..e280eee710dea9872ac236af834601d1d98a79ef 100644
--- a/matlab/PlotPosteriorDistributions.m
+++ b/matlab/PlotPosteriorDistributions.m
@@ -1,6 +1,5 @@
 function oo_ = PlotPosteriorDistributions(estim_params_, M_, options_, bayestopt_, oo_)
-
-% function PlotPosteriorDistributions()
+% oo_ = PlotPosteriorDistributions(estim_params_, M_, options_, bayestopt_, oo_)
 % plots posterior distributions
 %
 % INPUTS
@@ -36,7 +35,6 @@ latexDirectoryName = CheckPath('latex',M_.dname);
 graphDirectoryName = CheckPath('graphs',M_.dname);
 
 TeX     = options_.TeX;
-nblck   = options_.mh_nblck;
 nvx     = estim_params_.nvx;
 nvn     = estim_params_.nvn;
 ncx     = estim_params_.ncx;
@@ -66,7 +64,7 @@ for i=1:npar
         hh_fig=dyn_figure(options_.nodisplay, 'Name', figurename);
     end
     [nam,texnam] = get_the_name(i, TeX, M_, estim_params_, options_.varobs);
-    [x2, f2, abscissa, dens, binf2, bsup2] = draw_prior_density(i, bayestopt_);
+    [x2, f2, ~, ~, binf2, bsup2] = draw_prior_density(i, bayestopt_);
     top2 = max(f2);
     if i <= nvx
         name = M_.exo_names{estim_params_.var_exo(i,1)};
diff --git a/matlab/check_prior_bounds.m b/matlab/check_prior_bounds.m
index 14d93cfd67b547ad80b52aeadec68e43d1fd05f7..bf77952d6325d60bd6031be733a278ce2e08263d 100644
--- a/matlab/check_prior_bounds.m
+++ b/matlab/check_prior_bounds.m
@@ -1,10 +1,9 @@
 function check_prior_bounds(xparam1,bounds,M_,estim_params_,options_,bayestopt_)
-% function check_prior_bounds(xparam1,bounds,M_,estim_params_,options_)
+% function check_prior_bounds(xparam1,bounds,M_,estim_params_,options_,bayestopt_)
 % checks the parameter vector of violations of the prior bounds
 % Inputs:
 %   -xparam1        [double]    vector of parameters to be estimated (initial values)
-%   -bounds         [vector]    vector containing the lower and upper
-%   bounds
+%   -bounds         [vector]    vector containing the lower and upper bounds
 %   -M_             [structure] characterizing the model.
 %   -estim_params_  [structure] characterizing parameters to be estimated
 %   -options_       [structure] characterizing the options
diff --git a/matlab/fjaco.m b/matlab/fjaco.m
index e3a5e913e7b9b33cd8296024ad1af6e3d45d4549..3d41787b15eef7a0c59e1922325460fc137de514 100644
--- a/matlab/fjaco.m
+++ b/matlab/fjaco.m
@@ -1,5 +1,5 @@
 function fjac = fjaco(f,x,varargin)
-
+% fjac = fjaco(f,x,varargin)
 % FJACO Computes two-sided finite difference Jacobian
 % USAGE
 %   fjac = fjaco(f,x,P1,P2,...)
diff --git a/matlab/mh_autocorrelation_function.m b/matlab/mh_autocorrelation_function.m
index eb659f68653f879a8a43e64bf0136f634dff4e08..cf10a82798c58ac95d307820db9343524dd737c2 100644
--- a/matlab/mh_autocorrelation_function.m
+++ b/matlab/mh_autocorrelation_function.m
@@ -1,10 +1,9 @@
 function mh_autocorrelation_function(options_,M_,estim_params_,type,blck,name1,name2)
+% mh_autocorrelation_function(options_,M_,estim_params_,type,blck,name1,name2)
 % This function plots the autocorrelation of the sampled draws in the
 % posterior distribution.
 %
-%
 % INPUTS
-%
 %   options_        [structure]    Dynare structure.
 %   M_              [structure]    Dynare structure (related to model definition).
 %   estim_params_   [structure]    Dynare structure (related to estimation).
@@ -63,7 +62,7 @@ clear record;
 PosteriorDraws = GetAllPosteriorDraws(M_.dname, M_.fname, column, FirstMhFile, FirstLine, TotalNumberOfMhFiles, NumberOfDraws, nblck, blck);
 
 % Compute the autocorrelation function:
-[autocov,autocor] = sample_autocovariance(PosteriorDraws,options_.mh_autocorrelation_function_size);
+[~,autocor] = sample_autocovariance(PosteriorDraws,options_.mh_autocorrelation_function_size);
 
 % Plot the posterior draws:
 
@@ -101,7 +100,7 @@ axis tight
 if ~exist(M_.dname, 'dir')
     mkdir('.',M_.dname);
 end
-if ~exist([M_.dname filesep 'graphs'])
+if ~exist([M_.dname filesep 'graphs'],'dir')
     mkdir(M_.dname,'graphs');
 end
 
diff --git a/matlab/plot_priors.m b/matlab/plot_priors.m
index 50b7b6a2b3a3ca913d985eab857627510eb31640..63b811fd8bf4f5c8e1e1dfd96f5720946506694d 100644
--- a/matlab/plot_priors.m
+++ b/matlab/plot_priors.m
@@ -1,5 +1,5 @@
 function plot_priors(bayestopt_,M_,estim_params_,options_,optional_title)
-% function plot_priors
+% plot_priors(bayestopt_,M_,estim_params_,options_,optional_title)
 % plots prior density
 %
 % INPUTS
@@ -41,7 +41,7 @@ else
     figurename = optional_title;
 end
 npar = length(bayestopt_.p1);
-[nbplt,nr,nc,lr,lc,nstar] = pltorg(npar);
+[nbplt,nr,nc,~,~,nstar] = pltorg(npar);
 
 if TeX && any(strcmp('eps',cellstr(options_.graph_format)))
     fidTeX = fopen([latexDirectoryName filesep M_.fname '_Priors.tex'],'w');
@@ -59,7 +59,7 @@ for plt = 1:nbplt
     for index=1:nstar0
         names = [];
         i = (plt-1)*nstar + index;
-        [x,f,abscissa,dens,binf,bsup] = draw_prior_density(i,bayestopt_);
+        [x,f] = draw_prior_density(i,bayestopt_);
         [nam,texnam] = get_the_name(i,TeX,M_,estim_params_,options_.varobs);
         subplot(nr,nc,index)
         hh_plt = plot(x,f,'-k','linewidth',2);
diff --git a/matlab/print_table_prior.m b/matlab/print_table_prior.m
index 44096e5b2681d02b0c2acc6b81c355937301c977..b9253af4c7e9a2facb5d1bd6bbfd62dd078f9ae9 100644
--- a/matlab/print_table_prior.m
+++ b/matlab/print_table_prior.m
@@ -52,7 +52,7 @@ options_.prior_trunc = prior_trunc_backup ;
 RESIZE = false;
 
 for i=1:size(bayestopt_.name,1)
-    [Name,tmp] = get_the_name(i,1,M_,estim_params_,options_.varobs);
+    [Name,~] = get_the_name(i,1,M_,estim_params_,options_.varobs);
     if length(Name)>size(T1,2)
         resize = true;
     else
diff --git a/matlab/set_prior.m b/matlab/set_prior.m
index 635568dc861804863848ddc499ba25568e2b880e..e6739f4686f7433ef53e285cb02df6890626c5b1 100644
--- a/matlab/set_prior.m
+++ b/matlab/set_prior.m
@@ -133,7 +133,7 @@ if ncn
     bayestopt_.p4 = [ bayestopt_.p4; estim_params_.corrn(:,10)]; %take generalized distribution into account
     bayestopt_.jscale = [ bayestopt_.jscale; estim_params_.corrn(:,11)];
     baseid = length(bayestopt_.name);
-    bayestopt_.name = [bayestopt_.name; cell(ncn, 1)];;
+    bayestopt_.name = [bayestopt_.name; cell(ncn, 1)];
     for i=1:ncn
         k1 = estim_params_.corrn(i,1);
         k2 = estim_params_.corrn(i,2);
@@ -163,8 +163,8 @@ bayestopt_.p7 = bayestopt_.p6 ;
 
 %% check for point priors and disallow them as they do not work with MCMC
 if any(bayestopt_.p2 ==0)
-    error(sprintf(['Error in prior for %s: you cannot use a point prior in estimation. Either increase the prior standard deviation',...
-                   ' or fix the parameter completely.'], bayestopt_.name{bayestopt_.p2 ==0}))
+    error('Error in prior for %s: you cannot use a point prior in estimation. Either increase the prior standard deviation',...
+                   ' or fix the parameter completely.', bayestopt_.name{bayestopt_.p2 ==0})
 end
 
 % generalized location parameters by default for beta distribution
@@ -285,7 +285,7 @@ end
 CheckPath('prior',M_.dname);
 
 % I save the prior definition if the prior has changed.
-if exist([ M_.dname '/prior/definition.mat'])
+if exist([ M_.dname '/prior/definition.mat'],'file')
     old = load([M_.dname '/prior/definition.mat'],'bayestopt_');
     prior_has_changed = 0;
     if length(bayestopt_.p1)==length(old.bayestopt_.p1)
diff --git a/matlab/write_latex_prior_table.m b/matlab/write_latex_prior_table.m
index 51a003075682a63d8e18e3d8645d4913c787be3e..9dd0496d2acda9815ac4a23fd1e722f1d5da7764 100644
--- a/matlab/write_latex_prior_table.m
+++ b/matlab/write_latex_prior_table.m
@@ -28,7 +28,7 @@ function write_latex_prior_table
 % You should have received a copy of the GNU General Public License
 % along with Dynare.  If not, see <https://www.gnu.org/licenses/>.
 
-global M_ options_ bayestopt_ estim_params_
+global M_ options_ estim_params_
 
 if ~isbayes(estim_params_)
     fprintf('\nwrite_latex_prior_table:: No prior distributions detected. Skipping table creation.\n')
@@ -39,13 +39,13 @@ if (size(estim_params_.var_endo,1) || size(estim_params_.corrn,1))
     % Prior over measurement errors are defined...
     if ((isfield(options_,'varobs') && isempty(options_.varobs)) || ~isfield(options_,'varobs'))
         % ... But the list of observed variabled is not yet defined.
-        fprintf(['\nwrite_latex_prior_table:: varobs should be declared before. Skipping table creation.\n'])
+        fprintf('\nwrite_latex_prior_table:: varobs should be declared before. Skipping table creation.\n')
         return
     end
 end
 
 % Fill or update bayestopt_ structure
-[xparam1, estim_params_, BayesOptions, lb, ub, M_] = set_prior(estim_params_, M_, options_);
+[~, estim_params_, BayesOptions, ~, ~, M_] = set_prior(estim_params_, M_, options_);
 
 % Get untruncated bounds
 bounds = prior_bounds(BayesOptions, options_.prior_trunc);
@@ -112,7 +112,7 @@ fprintf(fidTeX,'\\endlastfoot\n');
 % Column 8: the upper bound of the interval containing 90% of the prior mass.
 PriorIntervals = prior_bounds(BayesOptions,(1-options_.prior_interval)/2) ;
 for i=1:size(BayesOptions.name,1)
-    [tmp,TexName] = get_the_name(i, 1, M_, estim_params_, options_.varobs);
+    [~,TexName] = get_the_name(i, 1, M_, estim_params_, options_.varobs);
     PriorShape = PriorNames{ BayesOptions.pshape(i) };
     PriorMean = BayesOptions.p1(i);
     PriorMode = BayesOptions.p5(i);