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

Dimension change for same matrix

Tags: None
(comma "," separated)
izabelain
Registered Member
Posts
6
Karma
0

Dimension change for same matrix

Thu Sep 29, 2011 11:35 am
Hi all,

I would like to ask a basic problem, I have two matrices say A,B...
A = [1;2] // 2x1 matrix
B = [1 2;3 4] // 2x2 matrix

During runtime, I would like to increase dimension. In matlab, I do by,

for i=1:3

A(:,i)=[2; 2] // increasing col
B(:,:,i)=[1 3;4 5] // increasing rows and col

end

Please help me how I can do it by using Eigen.....
Thanks in advance.
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: Dimension change for same matrix

Thu Sep 29, 2011 12:51 pm
the best is not doing so because this not memory efficient (lot of reallocation and copies) but you can use .conservativeResize(rows,cols) for that.
jitseniesen
Registered Member
Posts
204
Karma
2

Re: Dimension change for same matrix

Thu Sep 29, 2011 12:52 pm
Here is an example:

Code: Select all
MatrixXd A(2,1);
A << 1,2;                      // equivalent to A = [1;2] in Matlab
for (int i=2; i<4; ++i) {
   A.conservativeResize(2,i);  // make A of size 2-by-i by adding an extra column
   A.col(i) << 2,2;            // initialize the column
}
izabelain
Registered Member
Posts
6
Karma
0
Thank you so much....


Bookmarks



Who is online

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