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

Mapping Custom Structures

Tags: None
(comma "," separated)
abrown
Registered Member
Posts
4
Karma
0

Mapping Custom Structures

Mon Jun 06, 2016 9:47 pm
I have a vector of structure's, and each struct holds 9 double values. I want to Map it to a MatrixXd, where each row is an element in the vector. Is this possible? And how do I do it? I thought it was something like:

Code: Select all
Eigen::Map<Eigen::MatrixXd > myMap(&myVector[0].station, myVector.size(), 9);


But apparently I'm way off base here.I am failing on the assertion "YOU_TRIED_CALLING_A_VECTOR_METHOD_ON_A_MATRIX".
Any help is greatly appreciated.
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: Mapping Custom Structures

Tue Jun 07, 2016 7:51 am
hm, this should work, except that by default MatrixXd is column major, so you should use:

Map<Matrix<double,Dynamic,9,RowMajor> > mymap(&(myVector[0].station), myVector.size(), 9);

if not, please post the precise error message with precise code.
abrown
Registered Member
Posts
4
Karma
0

Re: Mapping Custom Structures

Tue Jun 07, 2016 6:47 pm
ggael wrote:hm, this should work, except that by default MatrixXd is column major, so you should use:

Map<Matrix<double,Dynamic,9,RowMajor> > mymap(&(myVector[0].station), myVector.size(), 9);

if not, please post the precise error message with precise code.


Yep this worked as expected. Thanks for the response.


Bookmarks



Who is online

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