Created
March 17, 2020 03:11
-
-
Save insaneyilin/d08efa50a3dd6033ede2bc1259dbcd33 to your computer and use it in GitHub Desktop.
Print Eigen's Matrix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void PrintEigenMat(const Eigen::Ref<const Eigen::MatrixXd> &x, | |
const std::string mat_name) { | |
if (!mat_name.empty()) { | |
std::cout << mat_name << " =\n"; | |
} | |
const int rows = x.rows(); | |
const int cols = x.cols(); | |
char buf[200]; | |
for (int i = 0; i < rows; ++i) { | |
for (int j = 0; j < cols; ++j) { | |
double val = x(i, j); | |
sprintf(buf, "%.8lf", val); | |
std::cout << "\t" << std::setprecision(9) << buf; | |
} | |
std::cout << std::endl; | |
} | |
std::cout << std::endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment