Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

fewerbins

Decrease number of histogram bins

Syntax

N = fewerbins(h)
N = fewerbins(h,direction)

Description

example

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.

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)
h = 
  Histogram with properties:

             Data: [1000x1 double]
           Values: [1x23 double]
          NumBins: 23
         BinEdges: [1x24 double]
         BinWidth: 0.3000
        BinLimits: [-3.3000 3.6000]
    Normalization: 'count'
        FaceColor: 'auto'
        EdgeColor: [0 0 0]

  Show all properties

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

fewerbins(h);
fewerbins(h)
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].

Introduced in R2014b

Was this topic helpful?