diff --git a/matlab/dynasave.m b/matlab/dynasave.m
index 45642a8ca8e9cee49de5b2caadd27561efb0d4c4..d80aa98abc4002ca4f100aa89475646474f22267 100644
--- a/matlab/dynasave.m
+++ b/matlab/dynasave.m
@@ -1,6 +1,6 @@
-function dynasave(s, var_list)
+function dynasave(s,var_list)
 % function dynasave(s,var_list)
-% This optional command saves the simulation results in a .MAT file.
+% This command saves the simulation results in a .MAT file.
 %
 % INPUTS
 %    s:              filename
@@ -12,7 +12,7 @@ function dynasave(s, var_list)
 % SPECIAL REQUIREMENTS
 %    none
 
-% Copyright (C) 2001-2018 Dynare Team
+% Copyright (C) 2001-2020 Dynare Team
 %
 % This file is part of Dynare.
 %
@@ -39,20 +39,19 @@ if ~isfield(oo_, 'endo_simul') || isempty(oo_.endo_simul)
     error('dynasave:: The results structure does not contain simulated series. Maybe the periods option has not been set.')
 end
 
-n = length(var_list);
-ivar = zeros(n, 1);
-for i=1:n
-    i_tmp = strmatch(var_list{i}, M_.endo_names, 'exact');
-    if isempty(i_tmp)
-        error ('One of the specified variables does not exist') ;
+for i = 1:length(var_list)
+    idx = strcmp(var_list{i}, M_.endo_names);
+    if any(idx)
+        SaveStruct.(var_list{i}) = oo_.endo_simul(idx,:);
     else
-        ivar(i) = i_tmp;
+        idx = strcmp(var_list{i}, M_.exo_names);
+        if any(idx)
+            SaveStruct.(var_list{i}) = oo_.exo_simul(:,idx);
+        else
+            error(['Should not arrive here: ' var_list{i} ' not found in M_.endo_names or M_.exo_names']) ;
+        end
     end
 end
 
-eval([var_list{1} ' = oo_.endo_simul(ivar(1),:)'';'])
-eval(['save ' s ' ' var_list{1} ' -mat'])
-for dynare__i_ = 2:n
-    eval([var_list{dynare__i_} ' = oo_.endo_simul(ivar(dynare__i_),:)'';'])
-    eval(['save ' s ' ' var_list{dynare__i_} ' -append -mat'])
+save(s, '-struct', 'SaveStruct');
 end
diff --git a/matlab/dynatype.m b/matlab/dynatype.m
index 33f3182677b835effb5290980153897fbeb39389..c0fe8c4d3f6de57369d4061bf95c2a55c7ce6c95 100644
--- a/matlab/dynatype.m
+++ b/matlab/dynatype.m
@@ -1,6 +1,6 @@
 function dynatype (s,var_list)
 % function dynatype (s,var_list)
-% This optional command saves the simulation results in a text file. The name of each
+% This command saves the simulation results in a text file. The name of each
 % variable preceeds the corresponding results. This command must follow SIMUL.
 %
 % INPUTS
@@ -13,7 +13,7 @@ function dynatype (s,var_list)
 % SPECIAL REQUIREMENTS
 %   none
 
-% Copyright (C) 2001-2018 Dynare Team
+% Copyright (C) 2001-2020 Dynare Team
 %
 % This file is part of Dynare.
 %
@@ -32,29 +32,27 @@ function dynatype (s,var_list)
 
 global M_ oo_
 
-fid=fopen(s,'w') ;
+fid = fopen(s, 'w');
 
 if isempty(var_list)
     var_list = M_.endo_names(1:M_.orig_endo_nbr);
 end
 
-n = length(var_list);
-ivar = zeros(n,1);
-
-for i=1:n
-    i_tmp = strmatch(var_list{i}, M_.endo_names, 'exact');
-    if isempty(i_tmp)
-        error ('One of the specified variables does not exist') ;
+for i = 1:length(var_list)
+    idx = strcmp(var_list{i}, M_.endo_names);
+    if any(idx)
+        fprintf(fid, '%s\n', M_.endo_names{idx});
+        fprintf(fid, '%15.8g\n', oo_.endo_simul(idx,:)');
     else
-        ivar(i) = i_tmp;
+        idx = strcmp(var_list{i}, M_.exo_names);
+        if any(idx)
+            fprintf(fid, '%s\n', M_.exo_names{idx});
+            fprintf(fid, '%15.8g\n', oo_.exo_simul(:,idx));
+        else
+            error(['Should not arrive here: ' var_list{i} ' not found in M_.endo_names or M_.exo_names']) ;
+        end
     end
 end
 
-for i = 1:n
-    fprintf(fid,M_.endo_names{ivar(i)},'\n') ;
-    fprintf(fid,'\n') ;
-    fprintf(fid,'%15.8g\n',oo_.endo_simul(ivar(i),:)') ;
+fclose(fid);
 end
-fclose(fid) ;
-
-return ;
diff --git a/preprocessor b/preprocessor
index c23991017187b342b88bbc7684576182791b2658..da4ca9e32386618487a86ba8429cc0f9a26c9629 160000
--- a/preprocessor
+++ b/preprocessor
@@ -1 +1 @@
-Subproject commit c23991017187b342b88bbc7684576182791b2658
+Subproject commit da4ca9e32386618487a86ba8429cc0f9a26c9629
diff --git a/tests/ramst2.mod b/tests/ramst2.mod
index be2fe7a64345dd198850ed75620ffdbe0c7646dd..a9f92ccb2eae80b3f0ab81a87b584a6c2c2d507c 100644
--- a/tests/ramst2.mod
+++ b/tests/ramst2.mod
@@ -36,6 +36,9 @@ end;
 
 simul(periods=200);
 
+dynasave('myfile') c x k;
+dynatype('myfile1.txt') c x k;
+
 rplot c;
 rplot k;
 rplot dc;