From 01d6a1c70a1fdbaf1f523b2133fe394e91c3d34c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Charybdis=29?=
 <stepan@adjemian.eu>
Date: Tue, 26 Oct 2021 10:24:19 +0200
Subject: [PATCH] Fix wrong logic in test introduced in ceb67c42c.

(cherry picked from commit 5e0c4272cea0ec0a683cde74f16976294bad36d3)
---
 matlab/print_expectations.m | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)

diff --git a/matlab/print_expectations.m b/matlab/print_expectations.m
index f3eadd28d0..ea09238069 100644
--- a/matlab/print_expectations.m
+++ b/matlab/print_expectations.m
@@ -91,17 +91,15 @@ end
 expectationmodel = M_.(expectationmodelfield).(expectationmodelname);
 
 % Get the name of the associated VAR model and test its existence.
-if isfield(M_.(expectationmodelfield), 'auxiliary_model_type')
-    if ~isfield(M_.(expectationmodel.auxiliary_model_type), expectationmodel.auxiliary_model_name)
-        switch expectationmodelkind
-          case 'var'
-            error('Unknown VAR/TREND_COMPONENT model (%s) in VAR_EXPECTATION_MODEL (%s)!', expectationmodel.auxiliary_model_name, expectationmodelname)
-          case 'pac'
-            error('Unknown VAR/TREND_COMPONENT model (%s) in PAC_EXPECTATION_MODEL (%s)!', expectationmodel.auxiliary_model_name, expectationmodelname)
-          otherwise
-        end
+if isfield(expectationmodel, 'auxiliary_model_name') && ~isfield(M_.(expectationmodel.auxiliary_model_type), expectationmodel.auxiliary_model_name)
+    switch expectationmodelkind
+      case 'var'
+        error('Unknown VAR/TREND_COMPONENT model (%s) in VAR_EXPECTATION_MODEL (%s)!', expectationmodel.auxiliary_model_name, expectationmodelname)
+      case 'pac'
+        error('Unknown VAR/TREND_COMPONENT model (%s) in PAC_EXPECTATION_MODEL (%s)!', expectationmodel.auxiliary_model_name, expectationmodelname)
+      otherwise
     end
-else
+elseif isequal(expectationmodelkind, 'pac') && ~isfield(expectationmodel, 'auxiliary_model_name')
     error('print method does not work in PAC/MCE.')
 end
 
-- 
GitLab