我想为动态大小的矩阵分配一个向量。如以下代码所示:
Eigen::Vector3f VectorCam; // Vector in camera frame
Eigen::MatrixXf VectorsCam; // Matrix contains the vectors
for (int i=0; i<=theta1.size(); i++)
{
std::cout << "I'm In theta1.size for loop" << std::endl;
VectorCam << sin(theta1[i]), sin(theta2[i]), cos(theta1[i])*cos(theta2[i]);
std::cout << "theta1.size is:" << theta1.size() << std::endl;
std::cout << VectorCam << std::endl;
VectorsCam.col(i) = VectorCam; // Matrix of Camera Vectors
std::cout << "Vectorscam" << VectorsCam << std::endl;
}
在终端中我得到了这个(在####下面(!知道 for 循环仍处于第一次运行中,并且应该在退出之前至少运行 2 次!我认为问题出在VectorsCam.col(i(中
###### 我在θ1.大小循环 θ1.大小为:1 1 1 7.82347e-10 visual_servo_node:/usr/include/eigen3/Eigen/src/Core/Block.h:123: Eigen::Block<XprType,>::Block(XprType&, Eigen::Index( [with XprType = Eigen::Matrix<float,>; int BlockRows = -1; int BlockCols = 1; bool InnerPanel = true;Eigen::Index = long int]: Assertion '(i>=0( && ( ((BlockRows==1( && (BlockCols==XprType::ColsAtCompileTime( && i<xpr.rows(((>
在调用VectorsCam.col(i)
之前,您必须确保VectorsCam
至少有i+1
列。分配VectorsCam.col(i) = VectorCam;
时,VectorsCam
中的行数必须与VectorCam
中的行数相匹配。
循环写入之前
Eigen::MatrixXf VectorsCam(3, theta1.size()); // Matrix contains the vectors
(我假设循环是for (int i=0; i<theta1.size(); i++)