MRPT logo

mrpt::math::CHistogram Class Reference

This class provides an easy way of computing histograms for unidimensional real valued variables. More...

#include <mrpt/math/CHistogram.h>

List of all members.

Public Member Functions

 CHistogram (double min, double max, int nBins)
 Constructor
Exceptions:
std::exception On nBins<=0 or max<=min.

void clear ()
 Clear the histogram:.
void add (double x)
 Add an element to the histogram.
int getBinCount (int index)
 Retuns the elements count into the selected bin index, where first one is 0.
double getBinRatio (int index)
 Retuns the ratio in [0,1] range for the selected bin index, where first one is 0.

Private Attributes

double min
 Private members:.
double max
std::vector< int > bins
 The bins counter.
int count
 The total elements count.


Detailed Description

This class provides an easy way of computing histograms for unidimensional real valued variables.

How to use it:

        CHistogram              hist(0,100,10);
        hist.add(86);
        hist.add(7);
        hist.add(45);

        std::cout << hist.getBinCount(0) << std::endl;          // Result: "1"
        std::cout << hist.getBinRatio(0) << std::endl;          // Result: "0.33"

Definition at line 52 of file CHistogram.h.


Constructor & Destructor Documentation

mrpt::math::CHistogram::CHistogram ( double  min,
double  max,
int  nBins 
)

Constructor

Exceptions:
std::exception On nBins<=0 or max<=min.


Member Function Documentation

void mrpt::math::CHistogram::add ( double  x  ) 

Add an element to the histogram.

If element is out [min,max] it is ignored.

Referenced by mrpt::math::histogram().

void mrpt::math::CHistogram::clear (  ) 

Clear the histogram:.

int mrpt::math::CHistogram::getBinCount ( int  index  ) 

Retuns the elements count into the selected bin index, where first one is 0.

Exceptions:
std::exception On invalid index

Referenced by mrpt::math::histogram().

double mrpt::math::CHistogram::getBinRatio ( int  index  ) 

Retuns the ratio in [0,1] range for the selected bin index, where first one is 0.

It returns 0 if no elements have been added.

Exceptions:
std::exception On invalid index.

Referenced by mrpt::math::histogram().


Member Data Documentation

std::vector<int> mrpt::math::CHistogram::bins [private]

The bins counter.

Definition at line 61 of file CHistogram.h.

The total elements count.

Definition at line 65 of file CHistogram.h.

double mrpt::math::CHistogram::max [private]

Definition at line 57 of file CHistogram.h.

double mrpt::math::CHistogram::min [private]

Private members:.

Definition at line 57 of file CHistogram.h.




Page generated by Doxygen 1.5.8 for MRPT 0.6.5 SVN: at Thu Feb 26 02:18:33 EST 2009