diff --git a/preprocessor/DynamicModel.cc b/preprocessor/DynamicModel.cc
index 8d040ad4c3c2337a6b08552997ecb423e148912d..18034b10c55e323e78b643127a6226c7fd87de80 100644
--- a/preprocessor/DynamicModel.cc
+++ b/preprocessor/DynamicModel.cc
@@ -1224,6 +1224,7 @@ DynamicModel::writeDynamicCFile(const string &dynamic_basename) const
                     << "     v2 = mxGetPr(plhs[2]);" << endl
                     << "  }" << endl
                     << endl
+                    << "  v3 = NULL;" << endl
                     << " if (nlhs >= 4)" << endl
                     << "  {" << endl
                     << "     /* Set the output pointer to the output matrix v3. */" << endl