简体   繁体   English

如何将向量分配给特征中的矩阵

[英]How to assing a vector to a matrix in eigen

I want to assign a vector to a matrix of Dynamic size.我想将向量分配给动态大小的矩阵。 As in the following code:如以下代码所示:

    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;
        
    } 

in the terminal I'm getting this (below #### ).在终端中,我得到了这个(在 #### 下面)。 Knowing that the for loop is still in the first run and it is supposed to run at least 2 times before exiting !知道 for 循环仍在第一次运行中,它应该在退出之前运行至少 2 次! I thimk the problem is in VectorsCam.col(i)我认为问题出在 VectorsCam.col(i)

######## I'm In theta1.size for loop theta1.size is:1 1 1 7.82347e-10 visual_servo_node: /usr/include/eigen3/Eigen/src/Core/Block.h:123: Eigen::Block<XprType, BlockRows, BlockCols, InnerPanel>::Block(XprType&, Eigen::Index) [with XprType = Eigen::Matrix<float, -1, -1>; ######## 我在 theta1.size for loop theta1.size is:1 1 1 7.82347e-10 visual_servo_node: /usr/include/eigen3/Eigen/src/Core/Block.h:123: Eigen::Block<XprType, BlockRows, BlockCols, InnerPanel>::Block(XprType&, Eigen::Index) [with XprType = Eigen::Matrix<float, -1, -1>; int BlockRows = -1; int BlockRows = -1; int BlockCols = 1; int BlockCols = 1; bool InnerPanel = true;布尔内面板=真; Eigen::Index = long int]: Assertion `(i>=0) && ( ((BlockRows==1) && (BlockCols==XprType::ColsAtCompileTime) && i<xpr.rows()) ||((BlockRows==XprType::RowsAtCompileTime) && (BlockCols==1) && i<xpr.cols()))' failed. Eigen::Index = long int]: 断言 `(i>=0) && ( ((BlockRows==1) && (BlockCols==XprType::ColsAtCompileTime) && i<xpr.rows()) ||((BlockRows ==XprType::RowsAtCompileTime) && (BlockCols==1) && i<xpr.cols()))' 失败。 Aborted (core dumped)中止(核心转储)

Before calling VectorsCam.col(i) you must make sure, VectorsCam has at least i+1 columns.在调用VectorsCam.col(i)之前,您必须确保VectorsCam至少有i+1列。 And when assigning VectorsCam.col(i) = VectorCam;并且当分配VectorsCam.col(i) = VectorCam; the number of rows in VectorsCam must match the number of rows in VectorCam . VectorsCam 中的行数必须与VectorsCam中的行数VectorCam

Before the loop write循环前写

Eigen::MatrixXf VectorsCam(3, theta1.size()); // Matrix contains the vectors

(and I assume the loop was meant to be for (int i=0; i<theta1.size(); i++) ) (我假设循环是为了for (int i=0; i<theta1.size(); i++)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM