Main Content

fewerbins

Decrease number of histogram bins

Description

N = fewerbins(h) decreases the number of bins in histogram h by 10% (rounded down to the nearest integer) and returns the new number of bins.

For bivariate histograms, this decreases the bin count in both the x and y directions.

example

N = fewerbins(h,direction), where h must be a histogram2 object, only decreases the number of bins in the dimension specified by direction. The direction option can be 'x', 'y', or 'both'. The default value is 'both'.

Examples

collapse all

Plot a histogram of 1,000 random numbers and return a handle to the histogram object.

x = randn(1000,1);
h = histogram(x)

Figure contains an axes object. The axes object contains an object of type histogram.

h = 
  Histogram with properties:

             Data: [1000x1 double]
           Values: [3 1 2 15 17 27 53 79 85 101 127 110 124 95 67 32 27 16 6 6 4 1 2]
          NumBins: 23
         BinEdges: [-3.3000 -3.0000 -2.7000 -2.4000 -2.1000 -1.8000 -1.5000 -1.2000 -0.9000 -0.6000 -0.3000 0 0.3000 0.6000 0.9000 1.2000 1.5000 1.8000 2.1000 2.4000 2.7000 3 3.3000 3.6000]
         BinWidth: 0.3000
        BinLimits: [-3.3000 3.6000]
    Normalization: 'count'
        FaceColor: 'auto'
        EdgeColor: [0 0 0]

  Use GET to show all properties

Use fewerbins to decrease the number of bins in the histogram.

fewerbins(h);
fewerbins(h)

Figure contains an axes object. The axes object contains an object of type histogram.

ans = 
18

Input Arguments

collapse all

Input histogram, specified as a histogram or histogram2 object.

h cannot be a categorical histogram.

Direction to decrease the number of bins, specified as 'x', 'y', or 'both'. Specify 'x' or 'y' to only decrease the number of bins in that direction while leaving the number of bins in the other direction constant.

Output Arguments

collapse all

Number of bins, returned as a scalar or vector. N is the new number of bins for the histogram after increase. For bivariate histogram plots, N is a two-element vector, [nx ny].

Version History

Introduced in R2014b