My question is how to initialize an eigen Matrix, but NOT this way:
matrix << 1,0,1,0,
1,0,1,0,
1,0,1,0,
I have a Matrix that looks like the above one ( commas or no commas doesnt matter) stored in a txt file.
I already wrote a function to read in each line and put it into a vector now I want to create a matrix with this data
But it doesn' work and I cant find any page that explains how to assign data to a matrix without writing just the values.(like the example above)
All I need is the data from my file in an eigen Matrix
What I tried so far: (PS: had the idea with the iterators but i guess it will take too long with really big matrices, I just tried this example with a 1-2 dimensional matrix)
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;
}
Unfortunately cant just say Matrix.row(i) = vector.back()
that doesnt work.
BlockImpl
object. Can you show the code where the first argument you're passing to a function is a string? – Depute