0

I have an eigen Matrix A which has 4 rows & 2 columns. Also I have two eigen Matrices B and C both have 2 rows and 2 columns. I want to add that two Matrices one after other into my Matrix A. In order to do that one I used the following code which is apparently not correct. Any help is appreciated. Thank you.

 MatrixXd A(4,4);
 MatrixXd B(2,2);
 MatrixXd C(2,2);
 B << 1,2,
      3,4;
 C << 5,6,
      7,8;
 A <<  B, // Error message:
       C;

Error message:

 XprType& Eigen::CommaInitializer<MatrixType>::finished() [with XprType = Eigen::Matrix<double, -1, -1>]: Assertion `((m_row+m_currentBlockRows) == m_xpr.rows() || m_xpr.cols() == 0) && m_col == m_xpr.cols() && "Too few coefficients passed to comma initializer (operator<<)"' failed.

Required output:( 4 rows, 2 columns)

A = 1, 2,
    3, 4,
    5,6,
    7,8;
coderide
  • 93
  • 1
  • 1
  • 8
  • 3
    There seems to be nothing wrong apart from two missing semicolons in the declarations of `B` and `C`. I cannot reproduce the error. The code you posted works on my computer, and it gives the desired output. – RHertel Aug 09 '19 at 08:38
  • More examples in the Eigen doc. [Advanced initialization](https://eigen.tuxfamily.org/dox/group__TutorialAdvancedInitialization.html)... – Scheff's Cat Aug 09 '19 at 08:41
  • 1
    As @RHertel said, this works fine after adding two semicolons (and some stuff around to make it compile): https://godbolt.org/z/thq9Np – chtz Aug 09 '19 at 08:52
  • 1
    In your last edit you changed the size of `A` to `4 x 4`, but you expect a `4 x 2` sized output?! – chtz Aug 09 '19 at 08:54

0 Answers0