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

Working with blocks

Tags: None
(comma "," separated)
samaursa
Registered Member
Posts
2
Karma
0

Working with blocks

Sun Apr 24, 2011 3:42 pm
I am getting a block of a matrix like so:
Code: Select all
H.block(ii(0), ii(0), 2, lenx);


How do I go about assigning it to a local variable (which must be...? Eigen::Block?) so that I can work with that block now instead of typing out all that code every time. I have looked through the documentation and know how to pass it as a function argument, but how do I create a local variable of the block to store it temporarily and at the same time affect the original matrix when the block elements change?

As you can tell, I am also new to template programming, so this is confusing me a little bit :)
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: Working with blocks

Sun Apr 24, 2011 4:43 pm
here you go:

Block<typeof_H> block_of_H = H.block(ii(0), ii(0), 2, lenx);
samaursa
Registered Member
Posts
2
Karma
0

Re: Working with blocks

Mon Apr 25, 2011 12:55 am
Excellent, thanks! Follow up question, what should I do in the following two cases:

1) I want the block to change the original matrix. So when I change the elements in the block, the original matrix reflects the change
2) I want the block to NOT change the original matrix
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: Working with blocks

Tue Apr 26, 2011 5:10 pm
for case 1: see my previous reply

for case 2: copy the block to a temporary:

MatrixXd H;
// ...
MatrixXd block_of_H = H.block(ii(0), ii(0), 2, lenx);


Bookmarks



Who is online

Registered users: bartoloni, Bing [Bot], Evergrowing, Google [Bot], q.ignora