I have a very large vector of vectors that I want to split into N-many sub-vectors (of vectors) via a function. The function will then perform some algorithmic routines on these sub-vectors but not return anything. I know how many sub-vectors (of vectors) that I want to split the original vector of vectors into (although NOT at compile time), and I am not sure how I am to create N-many sub-vectors of vectors within the function at runtime.
Usually, if you are splitting a vector into n-many sub-vectors, you would create a vector of vectors to store each sub-vector, especially if you require that the scope of these sub-vectors extends beyond the loop you are using to perform the splitting. Am I looking for (for lack of better description) a "four dimensional vector" to store these sub-vectors of vectors?
To clarify, say I have a vector of vectors that looks like so:
vec = { {945,1,1.0882222739646},
{955,1,1.08030633720477},
{965,1,1.06095611392935},
{975,1,1.0736443050851},
{985,1,1.04649065403142},
{995,1,1.06294684603874},
{1005,1,1.065654589561},
{1015,1,1.0668922119373},
{1025,1,1.03109676962124},
{1035,1,1.08430139146623} }
and I want to split it into 5 (determined at runtime) sub-vectors of vectors like so:
vec1 = { {945,1,1.0882222739646},
{955,1,1.08030633720477} }
vec2 = { {965,1,1.06095611392935},
{975,1,1.0736443050851} }
vec3 = { {985,1,1.04649065403142},
{995,1,1.06294684603874} }
vec4 = { {1005,1,1.065654589561},
{1015,1,1.0668922119373} }
vec5 = { {1025,1,1.03109676962124},
{1035,1,1.08430139146623} }
How exactly does one go about this? My function so far looks like so:
void calc_frac_block (vector<vector <double> > conc_data, vector<int> expidx)
{
// First, we need to create n-many vectors of vectors corresponding to the size of expidx
int expidx_size = expidx.size();
cout << "Size of expidx is: " << expidx_size << endl;
// Now we find the size of each subvector of vectors by diving conc_data by expidx_size
int subvec_size = conc_data.size() / expidx_size; // Will always be a whole number
cout << "Size of each subvector is: " << subvec_size << endl;
// NOW I HAVE THE NUMBER OF SUB-VECTORS OF VECTORS AND THE SIZE OF EACH... HOW TO PROCEED?
}
Any pointers would be helpful. I am using C++11 so solutions involving features therein are acceptable ;)
Aucun commentaire:
Enregistrer un commentaire