视觉slam|Eigen学习——Eigen Matrix删除矩阵某一行或某一列

Talk is cheap, show you the code:
删除矩阵某一行:

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

【视觉slam|Eigen学习——Eigen Matrix删除矩阵某一行或某一列】参考方法:链接

    推荐阅读