Registered Member
|
Hello, I have recently switched to using Eigen's Matrix objects as opposed to writing my own 2D vectors. However, I am confused about accessing the coefficient of a vector. The tutorial indicates that one should use the overloaded parentheses operator, as in matrix(i)(j) = value;
Now, I am developing a project in MS VS 2013 Express that makes use of vectors and matrices. I have a header file where for convenience I declare a private generic matrix that will grow in column size: MatrixXd jointVariables; Now, I initialize jointVariables in an implementation file be a 6x1 matrix and set all the coefficients to zero through an appropriate function: void BFGS::initializeJointVariables() { // Resize the Matrix to be 6x1 jointVariables.resize(6, 1); // Reset all coefficients to zero for (int count = 0; count < 5; count++) jointVariables.row(count).setZero(); } So far, this is good. However, at one point I must pass in the values from a vector into jointVariables, turning it into a column vector that will later grow in column size (hence the matrix). This is done through another function: void BFGS::setJointVariables(const vector<double> &initialGuess) { // Set jointVariables to be a 6x1 vector initializeJointVariables(); // Set the first column to be the contents of initialGuess for (int count = 0; count < 6; count++) jointVariables(count)(0) = initialGuess[count]; } According to the tutorial, the syntax I use to assign the contents of the initialGuess vector to the jointVariables matrix should be perfectly acceptable. However, I am getting a compiler error/warning: "Error: expression preceding parentheses of apparent call must have (pointer-to-) function type" This would make perfect sense if the parenthesis operators weren't overloaded... which they are. However, I am stuck at this point and not sure what is causing this or how to fix it. Is it something in my decleration of a MatrixXd type? Just to make sure, I inserted the snipped from the tutorial into my code to check if that worked: (in header) private: MatrixXd m; (in implementation file) void BFGS::setJointVariables(const vector<double> &initialGuess) { // Set jointVariables to be a 6x1 vector initializeJointVariables(); m(0, 0) = 3; // Perfectly okay jointVariables(0)(0) = 3; // NOT okay } Can someone please help me out? Do I need to provide more information or am I being too vague? |
Registered Member
|
Nevermind, I figured it out. I should be doing (value, value) instead of (value)(value). My bad.
|
Registered users: Bing [Bot], Google [Bot], Yahoo [Bot]