From f53b6cc6fbe3f7624ce92e2c5daa1d431dcd07e0 Mon Sep 17 00:00:00 2001
From: Johannes Pfeifer <jpfeifer@gmx.de>
Date: Wed, 27 Dec 2023 14:58:10 +0100
Subject: [PATCH] :bug: makedataset.m: correct error message with first_obs
 specified

(cherry picked from commit 8f07f371387246744acd0dbf8d06b2198baa8ef6)
---
 matlab/utilities/dataset/makedataset.m | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/matlab/utilities/dataset/makedataset.m b/matlab/utilities/dataset/makedataset.m
index 4303b3df8b..7455aefb1d 100644
--- a/matlab/utilities/dataset/makedataset.m
+++ b/matlab/utilities/dataset/makedataset.m
@@ -242,8 +242,14 @@ if newdatainterface
     end
 else
     % ...  or check that nobs is smaller than the number of observations in dataset_.
-    if nobs>dataset_.nobs
-        error('makedataset: nobs (%s) cannot be greater than the last date in the dataset (%s)!', num2str(nobs), num2str(dataset_.nobs))
+    if FIRSTOBS>dataset_.dates(1)
+        if FIRSTOBS+nobs-1>dataset_.dates(end)
+            error('makedataset: Given first_obs=%u and %u total observations in the dataset, the current nobs of %s must not be greater than %s!', options_.first_obs, dataset_.nobs, num2str(nobs), num2str(dataset_.nobs-find(dataset_.dates==FIRSTOBS)+1))
+        end
+    else
+        if nobs>dataset_.nobs
+            error('makedataset: nobs (%s) cannot be greater than the last date in the dataset (%s)!', num2str(nobs), num2str(dataset_.nobs))
+        end
     end
 end
 
-- 
GitLab