//
#include <Eigen/Dense>
#include <iostream>
using namespace Eigen;
// 格式化打印输出
//precision 精度:主要包括StreamPrecision与FullPrecision,默认为0
//flags 设置标号,默认为0
//coeffSeparator 同一行两个数的分隔符
//rowSeparator 两行之间的分隔符
//rowPrefix 每一行开头符号
//rowSuffix 每一行结束符号
//matPrefix 矩阵开始时符号
//matSuffix 矩阵结束时符号
IOFormat CommaInitFmt(StreamPrecision, DontAlignCols, ", ", ", ", "", "", " << ", ";");
IOFormat CleanFmt(4, 0, ", ", "\n", "[", "]");
IOFormat OctaveFmt(StreamPrecision, 0, ", ", ";\n", "", "", "[", "]");
IOFormat HeavyFmt(FullPrecision, 0, ", ", ";\n", "[", "]", "[", "]");
int main()
{
// 生成(-1, 1)的均匀分布的随机数
MatrixXd A = MatrixXd::Random(4, 4);
std::cout << A.format(CommaInitFmt) << std::endl;
std::cout << A.format(CleanFmt) << std::endl;
std::cout << A.format(OctaveFmt) << std::endl;
std::cout << A.format(HeavyFmt) << std::endl;
system("pause");
return 0;
}
结果:
<< -0.997497, 0.170019, 0.64568, 0.421003, 0.127171, -0.0402539, 0.49321, 0.0270699, -0.613392, -0.299417, -0.651784, -0.39201, 0.617481, 0.791925, 0.717887, -0.970031;
[ -0.9975, 0.17, 0.6457, 0.421]
[ 0.1272, -0.04025, 0.4932, 0.02707]
[ -0.6134, -0.2994, -0.6518, -0.392]
[ 0.6175, 0.7919, 0.7179, -0.97]
[-0.997497, 0.170019, 0.64568, 0.421003;
0.127171, -0.0402539, 0.49321, 0.0270699;
-0.613392, -0.299417, -0.651784, -0.39201;
0.617481, 0.791925, 0.717887, -0.970031]
[[ -0.997497482222968, 0.17001861629078, 0.645680104983673, 0.421002838221381];
[ 0.12717062898648, -0.0402539139988403, 0.493209631641591, 0.0270699179052094];
[ -0.613391521958068, -0.299417096469008, -0.651783806878872, -0.392010254219184];
[ 0.617481002227851, 0.791924802392651, 0.717886898403882, -0.970030823694571]]