diff --git a/preprocessor/ModFile.cc b/preprocessor/ModFile.cc
index d5f06f0938ec0086058ebed600cb7f6207a63f5a..82209665c8e06d97ce880b15c6ca0ff41c061ae2 100644
--- a/preprocessor/ModFile.cc
+++ b/preprocessor/ModFile.cc
@@ -384,7 +384,13 @@ ModFile::writeOutputFiles(const string &basename, bool clear_all, bool console,
               << "%           from model file (.mod)" << endl << endl;
 
   if (clear_all)
-    mOutputFile << "clear all" << endl;
+    {
+      mOutputFile << "if exist('OCTAVE_VERSION')" << endl
+		  << "  clear -all" << endl
+		  << "else" << endl 
+		  << "  clear all" << endl
+		  << "end" << endl;
+    }
 
   mOutputFile << "tic;" << endl
               << "global M_ oo_ options_ ys0_ ex0_" << endl