diff --git a/matlab/dynare_estimation_1.m b/matlab/dynare_estimation_1.m
index a4b4166145fae3a0184c98d5bf5d1c1d7bf32583..3fe420a2bfc85aab6dde28eca940e8991c5fe9aa 100644
--- a/matlab/dynare_estimation_1.m
+++ b/matlab/dynare_estimation_1.m
@@ -609,10 +609,10 @@ if (~((any(bayestopt_.pshape > 0) && options_.mh_replic) || (any(bayestopt_.psha
     if nvn
         number_of_plots_to_draw = 0;
         index = [];
-        for i=1:n_varobs
-            if max(abs(measurement_error)) > 0.000000001
+        for obs_iter=1:n_varobs
+            if max(abs(measurement_error(obs_iter,:))) > 0.0000001
                 number_of_plots_to_draw = number_of_plots_to_draw + 1;
-                index = cat(1,index,i);
+                index = cat(1,index,obs_iter);
             end
         end
         if ~options_.nograph
@@ -627,7 +627,7 @@ if (~((any(bayestopt_.pshape > 0) && options_.mh_replic) || (any(bayestopt_.psha
                 fh = dyn_figure(options_.nodisplay,'Name','Smoothed observation errors');
                 NAMES = [];
                 if options_.TeX, TeXNAMES = []; end
-                nstar0=min(nstar,number_of_plots_to_draw-(nbplt-1)*nstar);
+                nstar0=min(nstar,number_of_plots_to_draw-(plt-1)*nstar);
                 if gend==1
                     marker_string{1,1}='-ro';
                     marker_string{2,1}='-ko';