MATLAB实现频数直方图——hist的使用
MATLAB实现频数直方图——hist的使用hist" is short for "Histogram(直方图、柱状图)"。
1.N = hist(Y)
bins the elements of Y into 10 equally spaced containers and returns the number of elements in each container.If Y is a matrix, hist works down the columns.
(将向量Y的元素平均分到十个等间隔的容器中,并且返回每个容器的元素个数。如果Y是一个矩阵,hist指令逐列元素操作。Y为向量的情形见例1和2,为矩阵的情形见例3.)
例1.执行指令
>> Y = ;
>> hist(Y)
得到
http://www.logicdsp.com/data/attachment/forum/201306/21/225711vjl0qbgblvzqu0b7.jpg
0个蓝色方条,每个方条对应一个容器,其长度代表容器中数据的多少。由图知,容器中的数据量均为1。这个例子不够典型,见例2.
例2.执行指令
>>Y = ;
>> hist(Y)
得到
http://www.logicdsp.com/data/attachment/forum/201306/21/225712ia28pp52qvuy5yaq.jpg
Y最大为11,最小为1,故而将区间均分为10分,分别为, (2,3], (3,4], (4,5], (5,6], (6,7], (7,8], (8,9], (9,10], (10,11].
例3.当Y是矩阵时的情况。
执行指令:
>>Y = ;
>> hist(Y)
注意,Y为矩阵:
1.0000 2.5000 2.1000
3.0000 3.5000 6.0000
Y有三列元素,逐列元素产生对应的直方图。得到
http://www.logicdsp.com/data/attachment/forum/201306/21/225712v2ompta2fmfpzr72.jpg
观察此图和矩阵Y,由于Y的元素最大为1,最小为6,故而将区间以0.5的间隔划分为10个等长的子区间作为10个容器去容纳数据。图中有三种颜色的方条:蓝色,绿色和红色,分别对应Y中的第1,2,3列元素。如第一列元素为1和3,故而区间和(2.5,3]中有蓝色方条。
2.N = hist(Y,M)
where M is a scalar, uses M bins.(M是一个标量,表明使用M个箱子)
例1.执行指令
>> Y = ;
>>hist(Y, 6)
得到
http://www.logicdsp.com/data/attachment/forum/201306/21/225711vi1pokt3o1853yke.jpg
3.N = hist(Y,X)
where X is a vector, returns the distribution of Y among bins with centers specified by X.(X是向量,以X中的元素为区间中心可获得一系列区间,执行命令可获得Y在这些区间中的分布情况。) The first bin includes data between -inf and the first center and the last bin includes data between the last bin and inf. Note: Use HISTC if it is more natural to specify bin edges instead.
页:
[1]