(Not recommended) Histogram bin counts (2024)

(Not recommended) Histogram bin counts

collapse all in page

histc is not recommended. Use histcounts instead.

For more information, including suggestions on updating code, see Replace Discouraged Instances of hist and histc.

Syntax

bincounts = histc(x,binranges)

bincounts = histc(x,binranges,dim)

[bincounts,ind] =histc(___)

Description

example

bincounts = histc(x,binranges) counts the number of values in x that are within each specified bin range. The input, binranges, determines the endpoints for each bin. The output, bincounts, contains the number of elements from x in each bin.

  • If x is a vector, then histc returns bincounts as a vector of histogram bin counts.

  • If x is a matrix, then histc operates along each column of x and returns bincounts as a matrix of histogram bin counts for each column.

To plot the histogram, use bar(binranges,bincounts,'histc').

bincounts = histc(x,binranges,dim) operates along the dimension dim.

example

[bincounts,ind] =histc(___) returns ind, an array the same size as x indicating the bin number that each entry in x sorts into. Use this syntax with any of the previous input argument combinations.

Examples

collapse all

Create Histogram Plot

Open Live Script

Initialize the random number generator to make the output of randn repeatable.

rng(0,'twister')

Define x as 100 normally distributed random numbers. Define bin ranges between -4 and 4. Determine the number of values in x that are within each specified bin range. Return the number of elements in each bin in bincounts.

x = randn(100,1);binranges = -4:4;[bincounts] = histc(x,binranges)
bincounts = 9×1 0 2 17 28 32 16 3 2 0

To plot the histogram, use the bar function.

figurebar(binranges,bincounts,'histc')

(Not recommended) Histogram bin counts (1)

Return Bin Numbers for Histogram

Open Live Script

Defined ages as a vector of ages. Sort ages into bins with varying ranges between 0 and 75.

ages = [3,12,24,15,5,74,23,54,31,23,64,75];binranges = [0,10,25,50,75];[bincounts,ind] = histc(ages,binranges)
bincounts = 1×5 2 5 1 3 1
ind = 1×12 1 2 2 2 1 4 2 4 3 2 4 5

bincounts contains the number of values in each bin. ind indicates the bin numbers.

Input Arguments

collapse all

xValues to be sorted
vector | matrix

Values to be sorted, specified as a vector or a matrix. The bin counts do not include values in x that are NaN or that lie outside the specified bin ranges. If x contains complex values, then histc ignores the imaginary parts and uses only the real parts.

Data Types: single | double | int8 | int16 | int32 | uint8 | uint16 | uint32

binrangesBin ranges
vector | matrix

Bin ranges, specified as a vector of monotonically nondecreasing values or a matrix of monotonically nondecreasing values running down each successive column. The values in binranges determine the left and right endpoints for each bin. If binranges contains complex values, then histc ignores the imaginary parts and uses only the real parts.

If binranges is a matrix, then histc determines the bin ranges by using values running down successive columns. Each bin includes the left endpoint, but does not include the right endpoint. The last bin consists of the scalar value equal to last value in binranges.

For example, if binranges equals the vector [0,5,10,13], then histc creates four bins. The first bin includes values greater than or equal to 0 and strictly less than 5. The second bin includes values greater than or equal to 5 and less than 10, and so on. The last bin contains the scalar value 13.

Data Types: single | double | int8 | int16 | int32 | uint8 | uint16 | uint32

dimDimension along which to operate
scalar

Dimension along which to operate, specified as a scalar.

Output Arguments

collapse all

bincounts — Number of elements in each bin
vector | matrix

Number of elements in each bin, returned as a vector or a matrix. The last entry in bincounts is the number of values in x that equal the last entry in binranges.

ind — Bin index numbers
vector | matrix

Bin index numbers, returned as a vector or a matrix that is the same size as x.

Tips

  • If values in x lie outside the specified bin ranges, then histc does not include these values in the bin counts. Start and end the binranges vector with -inf and inf to ensure that all values in x are included in the bin counts.

Extended Capabilities

Version History

Introduced before R2006a

See Also

bar | hist | mode | histogram | histcounts

MATLAB Command

You clicked a link that corresponds to this MATLAB command:

 

Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.

(Not recommended) Histogram bin counts (2)

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list:

Americas

  • América Latina (Español)
  • Canada (English)
  • United States (English)

Europe

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom (English)

Asia Pacific

  • Australia (English)
  • India (English)
  • New Zealand (English)
  • 中国
  • 日本 (日本語)
  • 한국 (한국어)

Contact your local office

(Not recommended) Histogram bin counts (2024)

References

Top Articles
Why Leeks are Awesome (+ a Gratinéed Leeks Recipe)
50 Essential Holiday Recipes You Need in Your Arsenal
All Obituaries | Sneath Strilchuk Funeral Services | Funeral Home Roblin Dauphin Ste Rose McCreary MB
Computer Repair Tryon North Carolina
Qdoba Calorie Calc
Pulse Point Oxnard
Craigslist Greencastle
Restored Republic June 6 2023
Craigslist Placer County
Triple A Flat Tire Repair Cost
Tate Sweat Lpsg
Spur H0 » Details Trix H0 Profi Club Modell 2009
Best Fantasy Basketball Team
Schuylkill County Firewire
Abc Order Hs Login
Best Laundry Mat Near Me
The Land Book 9 Release Date 2023
Top Scorers Transfermarkt
Tenkiller Dam Release Schedule
Chase Bank Time Hours
Zitobox Tips And Tricks
Atl To London Google Flights
Glenwood Apartments Logan Utah
COUNTRY VOL 1 EICHBAUM COLLECTION (2024) WEB [FLAC] 16BITS 44 1KHZ
Clayton Grimm Siblings
PoE Reave Build 3.25 - Path of Exile: Settlers of Kalguur
Emerge Ortho Kronos
Lee Lucas Jaliyah Dad
Antonios Worcester Menu
Fortnite Fap Hero
Rugged Gentleman Barber Shop Martinsburg Wv
Dramacool Love In Contract
Erfahrungen mit Rheumaklinik Bad Aibling, Reha-Klinik, Bayern
Diminutiv: Definition, Bedeutung und Beispiele
Vernon Autoplex
Rule 34 Supreme Court: Key Insights and Implications
15 Best Things to Do in Tulare, CA - Travel Lens
Crystal Westbrooks Nipple
Target Minute Clinic Hours
Walmart Careers Application Part Time
Dr Roger Rosenstock Delray Beach
Giant Egg Classic Wow
Gregory (Five Nights at Freddy's)
Apartments for rent in Rotterdam
Mybrownhanky Com
4215 Tapper Rd Norton Oh 44203
Online-Shopping bei Temu: Solltest du lieber die Finger davon lassen?
The 7 best games similar to Among Us for Android - Sbenny’s Blog
Ericdoa Ethnicity
Mileage To Walmart
Cb2 South Coast Plaza
Latest Posts
Article information

Author: Kieth Sipes

Last Updated:

Views: 5973

Rating: 4.7 / 5 (67 voted)

Reviews: 82% of readers found this page helpful

Author information

Name: Kieth Sipes

Birthday: 2001-04-14

Address: Suite 492 62479 Champlin Loop, South Catrice, MS 57271

Phone: +9663362133320

Job: District Sales Analyst

Hobby: Digital arts, Dance, Ghost hunting, Worldbuilding, Kayaking, Table tennis, 3D printing

Introduction: My name is Kieth Sipes, I am a zany, rich, courageous, powerful, faithful, jolly, excited person who loves writing and wants to share my knowledge and understanding with you.