Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/130.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 访问C+中的矩阵行和列+;带本征_C++_Matrix_Eigen - Fatal编程技术网

C++ 访问C+中的矩阵行和列+;带本征

C++ 访问C+中的矩阵行和列+;带本征,c++,matrix,eigen,C++,Matrix,Eigen,假设我有一个C++中的矩阵: #include <iostream> #include <Eigen/Dense> using namespace Eigen; int main() { Matrix4d a; a << 1, 2, 3, 4; 5, 6, 7, 8; 9, 10, 11, 12; 13, 14, 15, 16; } #包括 #包括 使用名称空间

假设我有一个C++中的矩阵:

#include <iostream>  
#include <Eigen/Dense>  

using namespace Eigen;  

 int main()  
 {  
   Matrix4d a;  
   a << 1, 2, 3, 4;  
        5, 6, 7, 8;
        9, 10, 11, 12;
        13, 14, 15, 16;
 }
#包括
#包括
使用名称空间特征;
int main()
{  
Matrix4d a;

a…对不起,我弄明白了。 只需使用matrix.col()或matrix.row()即可


ezpz

当使用
eigen
库创建
矩阵时,您可以简单地使用:

matrix.col()
函数用于更改给定
矩阵中的列

matrix.row()
函数用于更改给定
矩阵中的行

单个列或行是块的情况

以下是一个例子:

#include <Eigen/Dense>
#include <iostream>
 
 
int main()
{
  Eigen::MatrixXf a(3,3);
  a << 1,2,3,
       4,5,6,
       7,8,9;
  std::cout << "Here is the matrix:" << std::endl << a<< std::endl;
  std::cout << "Here is the third row: " << a.row(2) << std::endl;
  a.col(1) += 2 * a.col(0);
  std::cout << "Adding 2 times the first column into the second column. Now the matrix will be:\n";
  std::cout << a << std::endl;
 return 0;  
}
#包括
#包括
int main()
{
本征::矩阵a(3,3);
A.