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

Copy a block of an array to another array

Tags: None
(comma "," separated)
donnss
Registered Member
Posts
7
Karma
0
Is it possible somehow to copy a block of an array
Code: Select all
array.block(index, index, index, index))

to another array at the specific location? Let's say, I have extracted a block of size 2x2 from one array and want to insert it into another array of size 4x4 but only at the beginning of this array that element (0,0), (0,1), (1,0) and (1,1) would be replaced by the block elements.
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
Yes, block expression are read-write, so, in your case:

B.block(0,0,2,2) = A.block(i,j,2,2);

or:

B.topLeftCorner(2,2) = A.block(,i,j,2,2);

or even:

B.topLeftCorner<2,2>() = A.block<2,2>(i,j);

The later version takes advantage that the block is 2x2 at compile-time.


Bookmarks



Who is online

Registered users: bartoloni, Bing [Bot], Evergrowing, Google [Bot], ourcraft