vector< vector<double> > out; //2D vector
ofstream myfile ("example.txt"); //outputfile
//the data contained in data[n][6] is put into the vector called 'out'.
for(int i = 1; i < iNumberOfFiles+1 ; i++) {
vector<double> row;
for (int n = 79; n < data.size(); n++) {
row.push_back(data[n][6]);
}
out.push_back(row);
}
//print the data in myfile
for(int i=0;i<out.size(); i++) {
for (int j=0;j<out[i].size(); j++)
myfile << out[i][j] << " ";
myfile << endl;
}
/*
Now here comes my problem, the data is put out as
a1 a2 a3 …. aN
b1 b2 b3 …. bN
. . . …. ...
x1 x2 x3 … xN
but I need the data in the following form:
a1 b1 . x1
a2 b2 . x2
. . . .
aN bN . xN
*/
/
//I though the data could be transposed like a 'normal' 2d array
vector< vector<double> > outtrans; //the 'transposed' vector
for(int i=0;i<out.size(); i++) {
for (int j=0;j<out[i].size(); j++){
outtrans[j][i] = out [i][j];
}
}
/* this is not working well however, when running this code, it (windows) says
file.exe is not functioning properly */
Does anyone have tips of how to transpose my vector properly (vector< vector<double> > out)?
Many thanks for your quick reply. Indeed it was getting stuck at my 'transposing', before which I had not allocated the memory properly.
Thanks for the references to available matrix libraries. I am aware of boost.org, but had never heard of Eigen.
Apart from transposing, I don't expect to be doing much other matrix operations.
Well, for the moment at least...currently I am just at the stage of getting data in the correct format for fitting later...