Jang
Jang

Reputation: 1

Extend size of Matrix in Eigen

I am using 'Eigen' library to do project using matrix manipulation. It's more powerful than Matlab in some area.

However, I want to extend a matrix to another.

That is, I want to create 2x4 matrix (A_extended) like below.

A=
    [1 2
     3 4]

B=
    [5 6
     7 8]

A_extended=
    [1 2 5 6
     3 4 7 8]

How can I do using Eigen library?

Upvotes: 0

Views: 411

Answers (1)

Gluttton
Gluttton

Reputation: 5988

#include <iostream>
#include <stdlib.h>
#include <Eigen/Dense>

int main (int argc, char * argv [])
{
    Eigen::MatrixXd m (2, 2);
    m << 1, 2, 3, 4;
    Eigen::MatrixXd n (2, 2);
    n << 5, 6, 7, 8;
    Eigen::MatrixXd k (2, 4);
    k << m, n;

    std::cout << k << std::endl;

    return EXIT_SUCCESS;
}

Output:

1 2 5 6
3 4 7 8

Upvotes: 2

Related Questions