我的问题是如何初始化一个特征矩阵,但不是这样:
matrix << 1,0,1,0,
1,0,1,0,
1,0,1,0,
Run Code Online (Sandbox Code Playgroud)
我有一个矩阵,看起来像上面的一个(逗号或没有逗号无关紧要)存储在txt文件中.
我已经编写了一个函数来读取每一行并将其放入一个向量中,现在我想用这个数据创建一个矩阵
但它不起作用,我找不到任何解释如何在不编写值的情况下将数据分配给矩阵的页面.(如上例所示)
我需要的只是我的文件中的一个特征矩阵的数据
到目前为止我尝试了什么:(PS:有迭代器的想法,但我想用真正的大矩阵需要太长时间,我只是用1-2维矩阵试过这个例子)
int readFromFile (const char * path, vector <string> & mv)
{
fstream file;
string line;
file.open(path);
while (getline(file,line))
{
mv.push_back(line);
}
file.close();
return 0;
}
typedef Matrix <int, 1, 2> MyMatrix;
int fromVectoEigen (vector<string> & source, MyMatrix & target)
{ //for (int i = source.size(); i<0 ; i--)
//{
string valuerow = source.back();
string::iterator it = valuerow.begin();
target.row(0)<< *it;
target.row(0)<<*it+1;
//source.pop_back();
//}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
不幸的是,只是说Matrix.row(i) …