Index: trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionMATLABFormatter.cs
===================================================================
--- trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionMATLABFormatter.cs	(revision 7521)
+++ trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionMATLABFormatter.cs	(revision 7630)
@@ -67,5 +67,28 @@
       currentLag = 0;
       currentIndexNumber = 0;
-      return FormatRecursively(symbolicExpressionTree.Root);
+
+      var stringBuilder = new StringBuilder();
+      stringBuilder.AppendLine("rows = ???");
+      stringBuilder.AppendLine(FormatOnlyExpression(symbolicExpressionTree.Root) + ";");
+      stringBuilder.AppendLine();
+      stringBuilder.AppendLine("function y = log_(x)");
+      stringBuilder.AppendLine("  if(x<=0) y = NaN;");
+      stringBuilder.AppendLine("  else     y = log(x);");
+      stringBuilder.AppendLine("  end");
+      stringBuilder.AppendLine("end");
+      stringBuilder.AppendLine();
+      stringBuilder.AppendLine("function y = fivePoint(f0, f1, f3, f4)");
+      stringBuilder.AppendLine("  y = (f0 + 2*f1 - 2*f3 - f4) / 8;");
+      stringBuilder.AppendLine("end");
+      return stringBuilder.ToString();
+    }
+
+    public string FormatOnlyExpression(ISymbolicExpressionTreeNode expressionNode)
+    {
+      var stringBuilder = new StringBuilder();
+      stringBuilder.AppendLine("  for " + CurrentIndexVariable + " = 1:1:rows");
+      stringBuilder.AppendLine("    estimated(" + CurrentIndexVariable + ") = " + FormatRecursively(expressionNode.GetSubtree(0)) + ";");
+      stringBuilder.AppendLine("  end;");
+      return stringBuilder.ToString();
     }
 
@@ -75,39 +98,14 @@
 
       if (symbol is ProgramRootSymbol) {
-        var variableNames = node.IterateNodesPostfix()
-          .OfType<VariableTreeNode>()
-          .Select(n => n.VariableName)
-          .Distinct()
-          .OrderBy(x => x);
-        stringBuilder.AppendLine("function test_model");
-        foreach (string variableName in variableNames)
-          stringBuilder.AppendLine("  " + variableName + " = Data(:, ???);");
-        stringBuilder.AppendLine("  for " + CurrentIndexVariable + " = size(Data,1):-1:1");
-        stringBuilder.AppendLine("    Target_estimated(" + CurrentIndexVariable + ") = " + FormatRecursively(node.GetSubtree(0)) + ";");
-        stringBuilder.AppendLine("  end");
-        stringBuilder.AppendLine("end");
-        stringBuilder.AppendLine();
-        stringBuilder.AppendLine("function y = log_(x)");
-        stringBuilder.AppendLine("  if(x<=0) y = NaN;");
-        stringBuilder.AppendLine("  else     y = log(x);");
-        stringBuilder.AppendLine("  end");
-        stringBuilder.AppendLine("end");
-        stringBuilder.AppendLine();
-        stringBuilder.AppendLine("function y = fivePoint(f0, f1, f3, f4)");
-        stringBuilder.AppendLine("  y = (f0 + 2*f1 - 2*f3 - f4) / 8;");
-        stringBuilder.AppendLine("end");
-        return stringBuilder.ToString();
-      }
-
-      if (symbol is StartSymbol)
+        stringBuilder.AppendLine(FormatRecursively(node.GetSubtree(0)));
+      } else if (symbol is StartSymbol)
         return FormatRecursively(node.GetSubtree(0));
-
-      stringBuilder.Append("(");
-
-      if (symbol is Addition) {
+      else if (symbol is Addition) {
+        stringBuilder.Append("(");
         for (int i = 0; i < node.SubtreeCount; i++) {
           if (i > 0) stringBuilder.Append("+");
           stringBuilder.Append(FormatRecursively(node.GetSubtree(i)));
         }
+        stringBuilder.Append(")");
       } else if (symbol is And) {
         stringBuilder.Append("((");
@@ -118,5 +116,6 @@
           stringBuilder.Append(")>0)");
         }
-        stringBuilder.Append(")-0.5)*2"); // MATLAB maps false and true to 0 and 1, resp., we map this result to -1.0 and +1.0, resp.
+        stringBuilder.Append(")-0.5)*2");
+        // MATLAB maps false and true to 0 and 1, resp., we map this result to -1.0 and +1.0, resp.
       } else if (symbol is Average) {
         stringBuilder.Append("(1/");
@@ -159,5 +158,6 @@
         stringBuilder.Append(">");
         stringBuilder.Append(FormatRecursively(node.GetSubtree(1)));
-        stringBuilder.Append(")-0.5)*2"); // MATLAB maps false and true to 0 and 1, resp., we map this result to -1.0 and +1.0, resp.
+        stringBuilder.Append(")-0.5)*2");
+        // MATLAB maps false and true to 0 and 1, resp., we map this result to -1.0 and +1.0, resp.
       } else if (symbol is IfThenElse) {
         stringBuilder.Append("(");
@@ -175,5 +175,6 @@
         stringBuilder.Append(laggedVariableTreeNode.Weight.ToString(CultureInfo.InvariantCulture));
         stringBuilder.Append("*");
-        stringBuilder.Append(laggedVariableTreeNode.VariableName + LagToString(currentLag + laggedVariableTreeNode.Lag));
+        stringBuilder.Append(laggedVariableTreeNode.VariableName +
+                             LagToString(currentLag + laggedVariableTreeNode.Lag));
       } else if (symbol is LessThan) {
         stringBuilder.Append("((");
@@ -181,5 +182,6 @@
         stringBuilder.Append("<");
         stringBuilder.Append(FormatRecursively(node.GetSubtree(1)));
-        stringBuilder.Append(")-0.5)*2"); // MATLAB maps false and true to 0 and 1, resp., we map this result to -1.0 and +1.0, resp.
+        stringBuilder.Append(")-0.5)*2");
+        // MATLAB maps false and true to 0 and 1, resp., we map this result to -1.0 and +1.0, resp.
       } else if (symbol is Logarithm) {
         stringBuilder.Append("log_(");
@@ -203,5 +205,6 @@
           stringBuilder.Append(")>0)");
         }
-        stringBuilder.Append(")-0.5)*2"); // MATLAB maps false and true to 0 and 1, resp., we map this result to -1.0 and +1.0, resp.
+        stringBuilder.Append(")-0.5)*2");
+        // MATLAB maps false and true to 0 and 1, resp., we map this result to -1.0 and +1.0, resp.
       } else if (symbol is Sine) {
         stringBuilder.Append("sin(");
@@ -262,5 +265,7 @@
         string prevCounterVariable = CurrentIndexVariable;
         string counterVariable = AllocateIndexVariable();
-        stringBuilder.AppendLine(" sum (map(@(" + counterVariable + ") " + FormatRecursively(node.GetSubtree(0)) + ", (" + prevCounterVariable + "+" + laggedNode.Lag + "):" + prevCounterVariable + "))");
+        stringBuilder.AppendLine(" sum (map(@(" + counterVariable + ") " + FormatRecursively(node.GetSubtree(0)) +
+                                 ", (" + prevCounterVariable + "+" + laggedNode.Lag + "):" + prevCounterVariable +
+                                 "))");
         ReleaseIndexVariable();
       } else if (symbol is TimeLag) {
@@ -272,11 +277,10 @@
         stringBuilder.Append("ERROR");
       }
-
-      stringBuilder.Append(")");
       return stringBuilder.ToString();
     }
 
 
-    private string LagToString(int lag) {
+    private string LagToString(int lag)
+    {
       if (lag < 0) {
         return "(" + CurrentIndexVariable + "" + lag + ")";
