美文网首页
eigen Dense矩阵拼接

eigen Dense矩阵拼接

作者: tsslisimin | 来源:发表于2019-01-18 11:13 被阅读0次
    • 矩阵拼接报错:

    /usr/include/eigen3/Eigen/src/Core/Block.h:141: Eigen::Block<XprType, BlockRows, BlockCols, InnerPanel>::Block(XprType&, Eigen::Block<XprType, BlockRows, BlockCols, InnerPanel>::Index, Eigen::Block<XprType, BlockRows, BlockCols, InnerPanel>::Index, Eigen::Block<XprType, BlockRows, BlockCols, InnerPanel>::Index, Eigen::Block<XprType, BlockRows, BlockCols, InnerPanel>::Index) [with XprType = Eigen::Matrix<double, -1, -1>; int BlockRows = -1; int BlockCols = -1; bool InnerPanel = false; Eigen::Block<XprType, BlockRows, BlockCols, InnerPanel>::Index = long int]: Assertion a_startRow >= 0 && blockRows >= 0 && a_startRow <= xpr.rows() - blockRows && a_startCol >= 0 && blockCols >= 0 && a_startCol <= xpr.cols() - blockCols' failed.

    • 解决方法
    MatrixXd A;
    MatrixXd B;
    MatrixXd C;
    A.resize(3, 3);   //注意矩阵拼接之前必须要确定大小,否则会上述报错
    B.resize(3, 9);   //注意矩阵拼接之前必须要确定大小,否则会上述报错
    C.resize(9, 3);   //注意矩阵拼接之前必须要确定大小,否则会上述报错
        A << 1, 2, 3,
             4, 5, 6,
             7, 8, 9;
        cout<<"A:"<<A<<endl;
        B << A,A,A; //水平拼接
        cout<<"B:"<<B<<endl;
      //垂直拼接
        C << A,
             A,
             A;
        cout<<"C:"<<C<<endl;
    
    • 输出结果如下:


      image.png

    相关文章

      网友评论

          本文标题:eigen Dense矩阵拼接

          本文链接:https://www.haomeiwen.com/subject/wongdqtx.html