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

Skipping Every n Elements in a Vector

Tags: None
(comma "," separated)
setareha
Registered Member
Posts
1
Karma
0

Skipping Every n Elements in a Vector

Mon Feb 01, 2016 10:27 pm
Hi,
Is there a way(except using a for loop) to skip elements when accessing the elements in a vector or matrix using Eigen ? I'm using Visual Studio 2013 and I'm programming in C++. I'm looking for an equivalent of A(1:2:p) in MATLAB which will give me every other element in an arbitrary vector A.
aluaces
Registered Member
Posts
13
Karma
0
OS
Yes, using a Eigen::Map and setting the Eigen::Stride parameter to "2".
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
To complete the previous answer:

Code: Select all
RowVectorXf v = RowVectorXf::LinSpaced(20,1,20);
Map<RowVectorXf,0,InnerStride<2> > v2(v.data(), v.size()/2);
std::cout << v2 << std::endl;


output:
Code: Select all
1  3  5  7  9 11 13 15 17 19


Bookmarks



Who is online

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