Eigen删除矩阵的某行或某列

删除矩阵某一行:

void RemoveRow(Eigen::Matrix3Xd& matrix, unsigned int rowToRemove) {
  unsigned int numRows = matrix.rows() - 1;
  unsigned int numCols = matrix.cols();
 
  if( rowToRemove < numRows ) {
   matrix.block(rowToRemove,0,numRows-rowToRemove,numCols) =
     matrix.block(rowToRemove+1,0,numRows-rowToRemove,numCols);
  }
 
  matrix.conservativeResize(numRows,numCols);
}

删除矩阵某一列:

void RemoveColumn(Eigen::Matrix3Xd& matrix, unsigned int colToRemove) {
  unsigned int numRows = matrix.rows();
  unsigned int numCols = matrix.cols() - 1;
 
  if( colToRemove < numCols ) {
    matrix.block(0, colToRemove, numRows, numCols - colToRemove) =
      matrix.block(0, colToRemove + 1, numRows, numCols - colToRemove);
  }
 
  matrix.conservativeResize(numRows,numCols);
}

REF:https://blog.csdn.net/Zkangsen/article/details/95756365


版权声明:本文为qq_42680785原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。