2010-07-09 00:42:23 +08:00
|
|
|
#include <iostream>
|
|
|
|
|
#include <Eigen/Dense>
|
|
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
|
Eigen::MatrixXf m(2, 4);
|
|
|
|
|
Eigen::VectorXf v(2);
|
2023-12-06 05:22:55 +08:00
|
|
|
|
2010-07-09 00:42:23 +08:00
|
|
|
m << 1, 23, 6, 9, 3, 11, 7, 2;
|
2023-12-06 05:22:55 +08:00
|
|
|
|
2010-07-09 00:42:23 +08:00
|
|
|
v << 2, 3;
|
|
|
|
|
|
2021-12-08 03:57:38 +08:00
|
|
|
Eigen::Index index;
|
2010-07-09 00:42:23 +08:00
|
|
|
// find nearest neighbour
|
|
|
|
|
(m.colwise() - v).colwise().squaredNorm().minCoeff(&index);
|
|
|
|
|
|
2021-12-08 03:57:38 +08:00
|
|
|
std::cout << "Nearest neighbour is column " << index << ":" << std::endl;
|
|
|
|
|
std::cout << m.col(index) << std::endl;
|
2010-07-09 00:42:23 +08:00
|
|
|
}
|