diff --git a/matlab/backward/backward_model_inversion.m b/matlab/backward/backward_model_inversion.m
index 8eb7c6f88f084e331328f33ed1c01792d2d89724..3643c9aa90ea7f2130f208c97c3bd31d604b97b6 100644
--- a/matlab/backward/backward_model_inversion.m
+++ b/matlab/backward/backward_model_inversion.m
@@ -93,7 +93,7 @@ for i=1:nyctrl
 end
 
 % Exogenous variables.
-X = exogenousvariables.data;
+X = exogenousvariables{exo_names{:}}.data;
 
 % Inversion of the model, solvers for the free endogenous and exogenous variables (call a Newton-like algorithm in each period).
 ity = 2;
diff --git a/matlab/model_inversion.m b/matlab/model_inversion.m
index 7f694cd5876a905b0364523a679f4d6448238a3e..865d21c4f6dc5fd2f4e98bbeaea583f6c4c815b4 100644
--- a/matlab/model_inversion.m
+++ b/matlab/model_inversion.m
@@ -77,6 +77,8 @@ end
 endo_names = DynareModel.endo_names;
 exo_names = DynareModel.exo_names;
 
+exogenousvariables = exogenousvariables{exo_names{:}};
+
 % Use specidalized routine if the model is backward looking.
 if ~DynareModel.maximum_lead
     if DynareModel.maximum_lag