Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

(C++) GetCumulativeHistogram

 

Math and std::vector code snippet to calculate a cumulative histogram from a histogram.

 

Before: 1, 2, 3, 4, 5

After : 1, 3, 6,10,15

 

* View the code of 'GetCumulativeHistogram' in plain text

 

 

//From htpp://www.richelbilderbeek.nl/CppGetCumulativeHistogram.htm

template <class T> const std::vector<T> GetCumulativeHistogram(const std::vector<T>& histogram)

{

std::vector<T> v(histogram.begin(),histogram.end() );

const int size = v.size();

for (int i=1; i!=size; ++i)

{

v[i] += v[i-1];

}

return v;

}

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.