#include "Eigen\Core"
using namespace Eigen;
template <typename Derived>
struct ColComparator
{
const Derived& matrix;
const int row;
ColComparator(const MatrixBase<Derived>& m, int r)
: matrix(m.derived()), row(r)
{}
bool operator()(int i, int j) const
{
return matrix(row, i) < matrix(row, j);
}
};
template <typename Derived>
struct RowComparator
{
const Derived& matrix;
const int col;
RowComparator(const MatrixBase<Derived>& m, int c)
: matrix(m.derived()), col(c)
{}
bool operator()(int i, int j) const
{
return matrix(i , col) < matrix(j , col);
}
};
template <typename Derived>
VectorXi columnArgSort(const MatrixBase<Derived>& matrix, int row)
{
// Start with indices [0 1 2 ... N-1]
VectorXi indexes = VectorXi::LinSpaced(matrix.cols(), 0, matrix.cols() - 1);
// Sort using our custom comparator, that will compare matrix values indirectly.
std::so
Eigen中与Matlab对应的 sort操作
最新推荐文章于 2022-08-29 21:01:42 发布