From a974c9be3ffa01da6c7a6dbca7fccac9afe9df44 Mon Sep 17 00:00:00 2001
From: Johannes Pfeifer <jpfeifer@gmx,de>
Date: Tue, 11 Mar 2014 12:11:47 +0100
Subject: [PATCH] Filter out stale or inconsistent number of observations.
 (cherry picked from commit 2a791e51dff2f565c2482010e753e78069ab29dd)

---
 matlab/bvar_toolbox.m | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/matlab/bvar_toolbox.m b/matlab/bvar_toolbox.m
index 1a218ab86c..76c95ef9de 100644
--- a/matlab/bvar_toolbox.m
+++ b/matlab/bvar_toolbox.m
@@ -65,6 +65,11 @@ global options_
 dataset = read_variables(options_.datafile, options_.varobs, [], options_.xls_sheet, options_.xls_range);
 options_ = set_default_option(options_, 'nobs', size(dataset,1)-options_.first_obs+1);
 
+if (options_.first_obs+options_.nobs-1)> size(dataset,1)
+    fprintf('Incorrect or missing specification of the number of observations. nobs can be at most %4u\n',size(dataset,1)-options_.first_obs+1);
+    error('Inconsistent number of observations.') 
+end
+
 % Parameters for prior
 if options_.first_obs + options_.presample <= nlags
     error('first_obs+presample should be > nlags (for initializing the VAR)')
-- 
GitLab