GNU Scientific Library – Reference Manual: Updating and accessing 2D histogram elements

Next: Searching 2D histogram ranges, Previous: Copying 2D Histograms, Up: Histograms [Index]

### 22.16 Updating and accessing 2D histogram elements

You can access the bins of a two-dimensional histogram either by specifying a pair of (x,y) coordinates or by using the bin indices (i,j) directly. The functions for accessing the histogram through (x,y) coordinates use binary searches in the x and y directions to identify the bin which covers the appropriate range.

Function: int gsl_histogram2d_increment (gsl_histogram2d * h, double x, double y)

  This function updates the histogram h by adding one (1.0) to the bin whose x and y ranges contain the coordinates (x,y).

  If the point (x,y) lies inside the valid ranges of the histogram then the function returns zero to indicate success. If (x,y) lies outside the limits of the histogram then the function returns `GSL_EDOM`, and none of the bins are modified. The error handler is not called, since it is often necessary to compute histograms for a small range of a larger dataset, ignoring any coordinates outside the range of interest.

Function: int gsl_histogram2d_accumulate (gsl_histogram2d * h, double x, double y, double weight)

  This function is similar to `gsl_histogram2d_increment` but increases the value of the appropriate bin in the histogram h by the floating-point number weight.

Function: double gsl_histogram2d_get (const gsl_histogram2d * h, size_t i, size_t j)

  This function returns the contents of the (i,j)-th bin of the histogram h. If (i,j) lies outside the valid range of indices for the histogram then the error handler is called with an error code of `GSL_EDOM` and the function returns 0.

Function: int gsl_histogram2d_get_xrange (const gsl_histogram2d * h, size_t i, double * xlower, double * xupper)
Function: int gsl_histogram2d_get_yrange (const gsl_histogram2d * h, size_t j, double * ylower, double * yupper)

  These functions find the upper and lower range limits of the i-th and j-th bins in the x and y directions of the histogram h. The range limits are stored in xlower and xupper or ylower and yupper. The lower limits are inclusive (i.e. events with these coordinates are included in the bin) and the upper limits are exclusive (i.e. events with the value of the upper limit are not included and fall in the neighboring higher bin, if it exists). The functions return 0 to indicate success. If i or j lies outside the valid range of indices for the histogram then the error handler is called with an error code of `GSL_EDOM`.

Function: double gsl_histogram2d_xmax (const gsl_histogram2d * h)
Function: double gsl_histogram2d_xmin (const gsl_histogram2d * h)
Function: size_t gsl_histogram2d_nx (const gsl_histogram2d * h)
Function: double gsl_histogram2d_ymax (const gsl_histogram2d * h)
Function: double gsl_histogram2d_ymin (const gsl_histogram2d * h)
Function: size_t gsl_histogram2d_ny (const gsl_histogram2d * h)

  These functions return the maximum upper and minimum lower range limits and the number of bins for the x and y directions of the histogram h. They provide a way of determining these values without accessing the `gsl_histogram2d` struct directly.

Function: void gsl_histogram2d_reset (gsl_histogram2d * h)

  This function resets all the bins of the histogram h to zero.

Next: Searching 2D histogram ranges, Previous: Copying 2D Histograms, Up: Histograms [Index]