adding values to a 3D array

I have a large data base that looks like the following:

Energy position

5.639792 1.36
4.844813 1.89
4.809105 2.33
3.954150 2.69
2.924234 3.42
1.532669 4.50
0.000000 5.63


The actual data contains thousands of rows. The first column of the data is the particle energy and second column is the particle position. The goal of the program is to create an array (or vector) that will store the values of the energy in different position bins. For the example data shown above, I would create an array with dimensions 1 x 6. For example, the first bin of the array would contain the sum of all energies with positions between 1.0 and 1.9. In this case, the first bin for the data shown above would have a value of 5.639792 + 4.844813 = 10.4846 (the sum of the first two energies). Similarly, the second position bin would contain 8.8452 the sum of the third and fourth energies. To implement this program I believe I need to use a floor ceiling function to assign the data into the proper position bin of the array. I'm not sure how to approach this problem. Any suggestions would be greatly appreciated.

Last edited on
I would use excel. If you really need a piece of software that does this (ie. you want to create your own program in C++) you'll probably have to do a few days/weeks of learning before you can properly implement it. Logically, here's how you would add the i*2th and (i*2-1)th value of an array into a 3rd array, if I understood you correctly:

1
2
3
4
5
6
float source[len];
float result[len/2];

for (i = 0; i != len/2; i++) {
    result[i]  = source[i*2-1] + source[i*2];
}


This relies on len being an even integer of course...
Last edited on
Do you want a histogram ?
http://www.cplusplus.com/forum/beginner/46926/#msg254928
Here's my post where someone had a similar problem.
Topic archived. No new replies allowed.