I need to create a MatrixXd combining multiple VectorXds as columns. I do not know the number of rows in the vector at the compile time (here I used 10
as size to show my problem)
I referred here and here I have the following codes
VectorXd vectOne= VectorXd(10);
VectorXd vectTwo = VectorXd(10);
VectorXd vectThree = VectorXd(10);
for (int i = 0; i < 10; i++) {
vectOne(i, 0) = i*2;
vectTwo(i, 0) = i*3;
vectThree(i, 0) = i*4;
}
MatrixXd m(10, 3);
//method 1 - FAILED
m.col(0) = vectOne;
m.col(1) = vectTwo;
m.col(2) = vectThree;
//method 2 -FAILED
m<< vectOne, vectTwo, vectThree;
Both do not work. I get errors like below.
Method 1 error: Assertion failed: startRow >= 0 && blockRows >= 0 && startRow <= xpr.rows() - blockRows && startCol >= 0 && blockCols >= 0 && startCol <= xpr.cols() - blockCols
Method 2 error: Assertion failed: rows == this->rows() && cols == this->cols() && "DenseBase::resize() does not actually allow to resize."
Please help to solve this.