From fdf6821d0bd6182a9a47cd1447aaa5f2812eb9e9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Charybdis=29?=
 <stepan@dynare.org>
Date: Wed, 11 Sep 2019 11:11:10 +0200
Subject: [PATCH] Generalized isconst routine.

---
 matlab/utilities/general/isconst.m | 24 +++++++++++++-----------
 1 file changed, 13 insertions(+), 11 deletions(-)

diff --git a/matlab/utilities/general/isconst.m b/matlab/utilities/general/isconst.m
index 28001ce4ec..e17a39b929 100644
--- a/matlab/utilities/general/isconst.m
+++ b/matlab/utilities/general/isconst.m
@@ -1,16 +1,14 @@
-function aa = isconst(y)
-% Returns 1 if vector y is constant, 0 otherwise.
+function A = isconst(B)
+
+% Returns an array of logicals, i-th element is `true` if column i of B is constant, `false` otherwise.
 %
 % INPUTS:
-%   yy        [double]    n*1 vector.
+% - B        [double]    n×m matrix.
 %
 % OUTPUTS
-%   aa        [integer]   scalar equal to 1 or 0.
-%
-% SPECIAL REQUIREMENTS
-%   none
+% - A        [logical]   1×m vector.
 
-% Copyright (C) 2008-2017 Dynare Team
+% Copyright © 2008-2019 Dynare Team
 %
 % This file is part of Dynare.
 %
@@ -26,7 +24,11 @@ function aa = isconst(y)
 %
 % You should have received a copy of the GNU General Public License
 % along with Dynare.  If not, see <http://www.gnu.org/licenses/>
-aa = 0;
-if all(abs(y(2:end)-y(1:end-1))<1e-10)
-    aa = 1;
+
+A = false(1, size(B, 2));
+
+for i = 1:size(B, 2)
+    if all(abs(B(2:end,i)-B(1:end-1,i))<1e-12)
+        A(i) = true;
+    end
 end
\ No newline at end of file
-- 
GitLab