title: Array of pointers to Eigen Matrices
body: <p>I am using MatrixXd matrices from Eigen on my code, and at a certain point I need a 3D one. Since Eigen does not have tridimensional matrix types, as it is optimized just for linear algebra, instead I am creating a pointer array of the MatrixXd type:</p>
  
  <pre><code>Eigen::MatrixXd *CVM =new Eigen::MatrixXd[100];
  for (int i = 0; i &lt; 100; i++){
     CVM[i]= Eigen::MatrixXd::Zero(5,5);
  }
  </code></pre>
  
  <p>However, later on I need to acess the values on this array, and for that I am doing something like:</p>
  
  <pre><code>for (int k = 0; k &lt; 100; k++){
     Eigen::MatrixXd* b=&amp;CVM[k];
  
     for (int i = 0; i &lt; 5; i++){
        for (int j = 0; j &lt; 5; j++){
           b-&gt;coeff(i,j)=47;
        }      
     }
  }
  </code></pre>
  
  <p>As <code>b</code> is a pointer and not the <code>MatrixXd</code> itself, <code>b(i,j)</code> obviously wouldn't work, so instead I am using the <code>coeff()</code> method, however, I get the following error:</p>
  
  <pre><code>error: assignment of read-only location ‘b-&gt;Eigen::Matrix&lt;double, -1, -1&gt;::&lt;anonymous&gt;.Eigen::PlainObjectBase&lt;Derived&gt;::coeff&lt;Eigen::Matrix&lt;double, -1, -1&gt; &gt;(((Eigen::PlainObjectBase&lt;Eigen::Matrix&lt;double, -1, -1&gt; &gt;::Index)i), ((Eigen::PlainObjectBase&lt;Eigen::Matrix&lt;double, -1, -1&gt; &gt;::Index)j))’
  </code></pre>
  
  <p>EDIT: output added</p>
  
  <pre><code>cout &lt;&lt; b &lt;&lt; endl;
  cout &lt;&lt; CVM[47] &lt;&lt; endl;
  
  
  0x1c34b00
  0 0 0 0 0
  0 0 0 0 0
  0 0 0 0 0
  0 0 0 0 0
  0 0 0 0 0
  </code></pre>