I am trying to extract data from multiple files into one output file.
At the moment I am able to extract the columns I want into a vector in a vector:
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)?