This forum has been archived. All content is frozen. Please use KDE Discuss instead.

newbie question: matrix concatenation

Tags: None
(comma "," separated)
pwa72
Registered Member
Posts
2
Karma
0
OS
Hi
I'm new to Eigen.

Apologies for a basic question. I'm trying to work out how I can simply concatenate matrices as per Matlab:

A = [ 1 2 3,
7 8 9,
13 14 15]


B = [4 5 6,
10 11 12,
16 17 18];

C = [A B];

ans =

1 2 3 4 5 6
7 8 9 10 11 12
13 14 15 16 17 18


I know I can copy a matrix A to C, and resize C, and then copy values across, but is there any way to do this in one to two lines of code?

Thanks,
Peter
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
2 lines:

C.resize(A.rows(),A.cols()+B.cols());
C << A, B;
pwa72
Registered Member
Posts
2
Karma
0
OS
Works perfectly, many thanks!


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], Yahoo [Bot]