From 4537f46647421fd4bd9e08580b320d66aee9221b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Charybdis=29?=
 <stephane.adjemian@univ-lemans.fr>
Date: Wed, 30 Sep 2015 22:52:48 +0200
Subject: [PATCH] Removed clear all for Matlab>=R2015b.

By default, Dynare clears the globals and functions containing
persistent variables. The behaviour of Dynare is not changed with
Matlab<R2015b or Octave.
---
 ModFile.cc | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/ModFile.cc b/ModFile.cc
index 6b376764..06e9f19a 100644
--- a/ModFile.cc
+++ b/ModFile.cc
@@ -575,7 +575,12 @@ ModFile::writeOutputFiles(const string &basename, bool clear_all, bool clear_glo
     mOutputFile << "warning off" << endl; // This will be executed *after* function warning_config()
 
   if (clear_all)
-    mOutputFile << "clear all" << endl;
+    mOutputFile << "if isoctave || matlab_ver_less_than('8.6')" << endl
+                << "    clear all" << endl
+		<< "else" << endl
+		<< "    clearvars -global" << endl
+		<< "    clear_persistent_variables(fileparts(which('dynare')))" << endl
+		<< "end" << endl;
   else if (clear_global)
     mOutputFile << "clear M_ options_ oo_ estim_params_ bayestopt_ dataset_;" << endl;
 
-- 
GitLab