Eigen笔记2:矩阵拼接
直接贴代码吧,使用的MatrixXd
和<<
运算符:
int main(int argc, char *argv[])
{
Eigen::MatrixXd B(2, 2);
B << 1, 2,
3, 4;
Eigen::MatrixXd C(2, 2);
C << 5, 6,
7, 8;
Eigen::MatrixXd D(2, 2);
D << 9, 10,
11, 12;
Eigen::MatrixXd H(2, 2);
H << 13, 14,
15, 16;
// Horizontal concatenation of B and C
Eigen::MatrixXd upper(B.rows(), B.cols() + C.cols());
upper << B, C;
std::cout << "Combined Matrix upper:\n" << upper << std::endl;
// Horizontal concatenation of D and H
Eigen::MatrixXd lower(D.rows()+ H.rows(), D.cols());
lower << D,
H;
std::cout << "Combined Matrix lower:\n" << lower << std::endl;
// Vertical concatenation of upper and lower
Eigen::MatrixXd A(B.rows() + D.rows(), B.cols() + C.cols());
A << B, C,
D, H;
std::cout << "Combined Matrix A:\n" << A << std::endl;
return 0;
}
效果如图
原文地址:https://blog.csdn.net/subtitle_/article/details/137695711
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!