| tonnot (335) | |
|
I have a unidimensional vector with 10 rows of data I'd like to fill my bidimensional vector[][] with the unidimensional vecto. Using the example, I will have a vector[10][1]. I dont want to fill the data using a loop Any idea ? Is there some method to construc the new vector directly from the unidimensional initial vector ? Thanks | |
|
|
|
| jeffbmartinez (31) | |||||
If you don't want to *use* a loop, I'm not sure. But if you simply don't want to type the loop, you can do the following:
I'm guessing memcpy uses some kind of loop to do it's job internally. Edit: An alternative that does not use a loop at all Depending on what you're actually trying to do, you could avoid copying altogether and use a pointer to the unidimensional data to dereference as a bidimensional:
Now, instead of bi[1][2], you say TreatAs2D(uni, 10, 1, 2)The second parameter is what tells TreatAs2D how many columns wide to treat your new "2D" array. | |||||
|
Last edited on
|
|||||
| tonnot (335) | |
| Thanks, I'm going to try it. | |
|
|
|
| Osmar (2) | |||||
|
Let me see if I got it right! The vector container has a ctor that allow you to fill elements in the vector like;
Right there is a vector of ten doubles filled with value .5 (0.5) each. Now for what I understand you want to fill a matrix of 10 elements initilized with another vector, say, our 'my_vec' in this example. If so, it could be done like this:
I'd prefer to wrap all that in a class of course, like this is horrible code but helps ilustrating... Hope it helps! | |||||
|
|
|||||