diff --git a/matlab/read_key_value_string.m b/matlab/read_key_value_string.m
index 446afd2f54b1b007e275f52c14da310fc0b7b972..c66bc7d500857904fecf96243977c4975cf4345e 100644
--- a/matlab/read_key_value_string.m
+++ b/matlab/read_key_value_string.m
@@ -4,7 +4,7 @@ function c = read_key_value_string(s)
 % estimation command) into a cell (first column for the option name ans second column for the
 % option value).
 
-% Copyright (C) 2011-2017 Dynare Team
+% Copyright © 2011-2021 Dynare Team
 %
 % This file is part of Dynare.
 %
@@ -21,6 +21,9 @@ function c = read_key_value_string(s)
 % You should have received a copy of the GNU General Public License
 % along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
 
+% Remove unnecessary spaces after commas.
+s = regexprep(s, ',\s*', ',');
+
 i_opening_bracket = strfind(s,'(');
 i_closing_bracket = strfind(s,')');