Documentation

histc

Histogram bin counts (not recommended; usehistcounts)

histcis not recommended. Usehistcountsinstead.

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

Syntax

bincounts = histc(x,binranges)
bincounts = histc(x,binranges,昏暗)
[bincounts,ind]= histc(___)

Description

example

bincounts= histc(x,binranges)counts the number of values inx在每个指定的垃圾箱范围内。The input,binranges, determines the endpoints for each bin. The output,bincounts, contains the number of elements fromxin each bin.

  • Ifx是一个向量,然后histcreturnsbincountsas a vector of histogram bin counts.

  • Ifx是矩阵,然后histc沿着每一列运行x并返回bincountsas a matrix of histogram bin counts for each column.

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

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

example

[bincounts,印第安]= histc(___)returns印第安,数组大小与x指示每个条目中的箱号xsorts into. Use this syntax with any of the previous input argument combinations.

Examples

collapse all

Initialize the random number generator to make the output ofrandnrepeatable.

rng(0,'twister')

Definexas 100 normally distributed random numbers. Define bin ranges between -4 and 4. Determine the number of values inx在每个指定的垃圾箱范围内。返回每个垃圾箱中的元素数量bincounts.

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

To plot the histogram, use thebarfunction.

figure bar(binranges,bincounts,'histc')

Defined年龄as a vector of ages. Sort年龄进垃圾箱不同范围between 0 and 75.

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

bincountscontains the number of values in each bin.印第安印第安icates the bin numbers.

Input Arguments

collapse all

要排序的值, specified as a vector or a matrix. The bin counts do not include values inx那是NaNor that lie outside the specified bin ranges. Ifxcontains complex values, thenhistc忽略虚构部分,仅使用真实零件。

Data Types:single|double|int8|INT16|INT32|int64|uint8|UINT16|uint32|uint64|logical

Bin ranges, specified as a vector of monotonically nondecreasing values or a matrix of monotonically nondecreasing values running down each successive column. The values inbinrangesdetermine the left and right endpoints for each bin. Ifbinrangescontains complex values, thenhistc忽略虚构部分,仅使用真实零件。

Ifbinranges是矩阵,然后histc通过使用向下连续的列来确定bin范围。每个垃圾箱包含左端点,但不包括右端点。最后一个bin由标量值组成,等于最后值binranges.

For example, ifbinrangesequals the vector[0,5,10,13], thenhistccreates 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|int64|uint8|UINT16|uint32|uint64|logical

Dimension along which to operate, specified as a scalar.

Data Types:single|double|int8|INT16|INT32|int64|uint8|UINT16|uint32|uint64|logical

Output Arguments

collapse all

Number of elements in each bin, returned as a vector or a matrix. The last entry inbincountsis the number of values inx等于最后一个条目binranges.

bin索引编号,返回为向量或矩阵,大小与x.

提示

  • 如果值在xlie outside the specified bin ranges, thenhistcdoes not include these values in the bin counts. Start and end thebinrangesvector with-infinfto ensure that all values inxare included in the bin counts.

Extended Capabilities

在R2006a之前引入

这个话题有帮助吗?