user3294195 - 7 months ago 72

C++ Question

If I want to concatenate two matrices

`A`

`B`

`using Eigen::MatrixXd;`

const MatrixXd A(n, p);

const MatrixXd B(n, q);

MatrixXd X(n, p+q);

X << A, B;

Now if

`n`

`p`

`q`

`X`

`A`

`B`

`X`

`Eigen::Ref<MatrixXd>`

Thanks.

Answer

No, `Ref`

is not designed for that. We/You would need to define a new expression for that, that could be called `Cat`

. If you only need to concatenate two matrices horizontally, in Eigen 3.3, this can be implemented in less than a dozen of lines of code as a nullary expression, see some exemple there.

Source (Stackoverflow)