Ich bin sehr neu in C++, aber dieser Code funktioniert in Mai-Anwendung.
Es funktioniert nur für volle dynamische Matrix aber kann es anpassen.
Wenn jemand einen besseren Weg hat, bitte zeigen Sie mir, ich möchte wirklich lernen.
template<typename ScalarType>
void MatrixXdRemoveCol(Eigen::Matrix<ScalarType,-1,-1,0,-1,-1> *mat, int colindex)
{
Eigen::Matrix<ScalarType,-1,-1,0,-1,-1> *auxmat = new Eigen::Matrix<ScalarType,-1,-1,0,-1,-1>;
*auxmat = *mat;
mat->resize(mat->rows(),mat->cols()-1);
int rightColsSize = auxmat->cols()-colindex-1;
mat->leftCols(colindex) = auxmat->leftCols(colindex);
mat->rightCols(rightColsSize) = auxmat->rightCols(rightColsSize);
}
template<typename ScalarType>
void MatrixXdRemoveCols(Eigen::Matrix<ScalarType,-1,-1,0,-1,-1> *mat, std::vector<int>* cols)
{
for(auto iter = cols->rbegin();iter != cols->rend();iter++)
MatrixXdRemoveCol<ScalarType>(mat,*iter);
}
template<typename ScalarType>
void MatrixXdRemoveRow(Eigen::Matrix<ScalarType,-1,-1,0,-1,-1> *mat, int rowindex)
{
Eigen::Matrix<ScalarType,-1,-1,0,-1,-1> *auxmat = new Eigen::Matrix<ScalarType,-1,-1,0,-1,-1>;
*auxmat = *mat;
mat->resize(mat->rows()-1,mat->cols());
int BottomRowsSize = auxmat->rows()-rowindex-1;
mat->topRows(rowindex) = auxmat->topRows(rowindex);
mat->bottomRows(BottomRowsSize) = auxmat->bottomRows(BottomRowsSize);
}
Ich glaube nicht, dass es eine andere Methode als die Verwendung der Blockoperationen gibt. – Jakob