title: Eigen library --> initialize matrix with data from file or existing std::vector<string> content (c++)
body: <p>My question is how to initialize an eigen Matrix, but <strong>NOT</strong> this way:</p>
  
  <pre><code>matrix &lt;&lt; 1,0,1,0,
            1,0,1,0,
            1,0,1,0,
  </code></pre>
  
  <p>I have a Matrix that looks like the above one ( commas or no commas doesnt matter)
  stored in a txt file.</p>
  
  <p>I already wrote a function to read in each line and put it into a vector
  now I want to create a matrix with this data</p>
  
  <p>But it doesn' work and I cant find any page that explains how to assign data to a matrix without writing just the values.(like the example above)</p>
  
  <p>All I need is the data from my file in an eigen Matrix </p>
  
  <p>What I tried so far: (PS: had the idea with the iterators but i guess it will take too long with really big matrices, I just tried this example with a 1-2 dimensional matrix) </p>
  
  <pre><code>int readFromFile (const char * path, vector &lt;string&gt; &amp; mv)
  {
      fstream file;
      string line;
      file.open(path);
  
      while (getline(file,line))
      {
          mv.push_back(line);
      }
      file.close();
      return 0;
  }
  
  
  typedef Matrix &lt;int, 1, 2&gt; MyMatrix;
  
  int fromVectoEigen (vector&lt;string&gt; &amp; source, MyMatrix &amp; target)
  {   //for (int i = source.size(); i&lt;0 ; i--)
      //{
  
          string valuerow = source.back();
          string::iterator it = valuerow.begin();
          target.row(0)&lt;&lt; *it;
          target.row(0)&lt;&lt;*it+1;
          //source.pop_back();
      //}
  
      return 0;
  }
  </code></pre>
  
  <p>Unfortunately cant just say <code>Matrix.row(i) = vector.back()</code> that doesnt work.</p>